Monday, October 20, 2008

[Tip] - Shrink an Image Control on a MS Access 2007 Report

If you have put an image control on a report and expected to see the "Can Shrink" property then you are going to be looking for a long time. So how do you shrink all that white space when there is no image for that field? Here's how:

1) In the Detail section put the following code in the "On format" event.
If IsNull(Me!image_field) Then
Me.imageControlName.Visible = False
Else
Me.imageControlName.Visible = False
End If

2) You also need to set "Can Shrink" to "Yes" in the Detail section.

3) Next the secret... you need to create an unbound textbox and stretch it the height of the image control. This control will be doing the shrinking when the image control is hidden.

Finished!

1 comment:

Remco said...

This doesn't work for me. In the details of my report I have a field Tekst121 which contains the link. I have an image control ProductLink. If the Tekst121 is empty I want it to shrink the image control and that line of the details. I can only get it to shrink and hide all the lines and image controls on the report, so also the ones that do contain an image.

This is my code:
Private Sub Details_Format(Cancel As Integer, FormatCount As Integer)

If Me.Tekst121.Value = "" Then
Me.ProductLink.Visible = False
ElseIf Not IsNull(Me.Tekst121) Then
Me.ProductLink.Visible = True
End If

End Sub

If I set the "true" to false, than it also hides them all. Can shrink and can grow in the details section are on. I put an unbound textbox called Tekst123 on the form