Shrinking & Sizing Reports with Images
|Images can take up a lot of space on a report, but if a particular record doesn't have an image the space is often left blank. As well as wasting space (and paper) this can be less visually appealing, and can make the report harder to follow.|
You have an opportunity to adjust the layout of the Detail Section when the report's 'Detail_Format' event fires. 'Detail_Format' fires for each record in the report, so by handling this event you can modify the size and position of controls on the Detail Section and the overall height of the Detail Section according to values in the record data. Using this approach you can avoid wasting space for records that do not have an image. The same technique can also be used to size images proportionally.
An important point to note about adjusting the height of the Detail Section is that the section can't be made smaller than the area occupied by any controls it contains. Consequently the control(s) must be shrunk before the section height can be shrunk (it is not sufficient to simply hide the controls). When designing a report for dynamic sizing, the easiest way is to place the image control at the bottom of the section (i.e. below any data that will always be visible) - in that way only the image control and section height needs to be shrunk. If controls are placed below the image control then additional code will be needed to move those controls up the page when no image is displayed (and back down if one is displayed).
Below is some sample code to illustrate this. The code assumes that the images are displayed from external (linked) files using an Image Control, and that the full image path is available in the 'ImagePath' field. The code checks for Null or empty values for 'ImagePath', and checks for values in 'ImagePath' where the file does not exist (using the 'Dir' command). You can adapt this for whatever file naming and path storage scheme you use. Alternatively, in the case of images stored in tables (as blobs, or using OLE Embedding) you can check the length of the field data to see if it contains an image by using the 'LenB' function, and resize OLE Frames or DBPix Image Controls in the same way.
|Const DetailMinHeight = 700|
Const ImgCtrlHeight = 2000
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
Dim strPath As String
If (Not IsNull([ImagePath])) Then strPath = [ImagePath]
If Len(strPath) > 0 And Len(Dir(strPath)) > Then
ImageCtrl.Picture = strPath
ImageCtrl.Height = ImgCtrlHeight
Me.Detail.Height = ImgCtrlHeight + DetailMinHeight
ImageCtrl.Picture = ""
ImageCtrl.Height = 0
Me.Detail.Height = DetailMinHeight
|Imaging for Access that's Easy, Efficient & Fast|
|NO OLE Bloat|
|NO App Dependencies|
|NO Complex Coding|
|NO Performance Penalty|| |
Microsoft and the Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.