Sizing an image control

R

Rob Parker

I have a subreport which contains only a detail section (set to Can
Shrink -Yes and Can Grow - Yes). The section contains two textboxes and an
image control. The image control, imgImage, is unbound, and the picture is
set by the following code at runtime:

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'Last edited: Rob Parker, 16 Feb 2006
On Error GoTo Detail_Format_Error

If Not IsNull(Me.Image) Then
' Me.imgImage.Visible = True
Me.imgImage.Height = 8 * 567 '8cm, in twips
Me.imgImage.Picture = Me.Image
Else
' Me.imgImage.Visible = False
Me.imgImage.Height = 0
Me.imgImage.Picture = ""
End If

On Error GoTo 0
Exit Sub

Detail_Format_Error:
If Err.Number = 2220 Then
Me.imgImage.Picture = ""
Else
MsgBox "Error " & Err.Number & " - " & Err.Description & vbCrLf & _
"in procedure Detail_Format" & vbCrLf & "of VBA Document
Report_sbrptArising_Remarks"
End If
End Sub

My problem is that the image control space is always present. Changing its
height has no effect, nor does changing its visibility (the commented-out
code lines are from trying that approach). The image control itself does
not have Can Shrink/Can Grow properties - hence my attempt to do this via
code. Putting the same code in the Detail_Print event also fails - in
particular, the attempt to change the image control height generates an
error, but the visible approach also fails.

How can I remove the white space when there is no picture to be displayed in
the image control?

TIA,

Rob
 
S

Stephen Lebans

With A2K and later you can resize the Detail section itself.

Me.Section(acDetail).Height = whatever

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
R

Rob Parker

Thanks Stephan,

I'll give that a try - I assume that I can do something like:
Me.Section(acDetail).Height = Me.Section(acDetail).Height - 2000
when there is no picture.

Rob
 
R

Rob Parker

Follow-up (solution):

Stephen's approach works, but it requires error trapping to ignore the
error that controls won't fit in the section. Here's my final code,
which works OK (it copes with the other text-boxes in the Detail
section growing/shrinking):

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'Last edited: Rob Parker, 17 Feb 2006
'Resizes Detail section when image is missing.
'Can Shrink/Can Grow does not deal with this, when image control
visibility is changed
'Need to trap error "Controls too large for section"
On Error GoTo Detail_Format_Error

If Not IsNull(Me.Image) Then
Me.imgImage.Height = 8 * 567 '8cm, in twips
Me.imgImage.Picture = Me.Image
Else
Me.imgImage.Height = 0
Me.imgImage.Picture = ""
Me.Section(acDetail).Height = Me.Section(acDetail).Height - 8 * 567
End If

On Error GoTo 0
Exit Sub

Detail_Format_Error:
If Err.Number = 2100 Then Resume Next 'ignore error regarding size
of section
If Err.Number = 2220 Then 'picture file not found
Me.imgImage.Picture = ""
Else
MsgBox "Error " & Err.Number & " - " & Err.Description & vbCrLf & _
"in procedure Detail_Format" & vbCrLf & "of VBA Document
Report_sbrptArising_Remarks"
End If
End Sub

Again, thanks for your help, Stephen.

Rob
 
S

Stephen Lebans

If you set the Image control's Visible prop to No, instead of resizing the
Image control's Height prop to 0, then you will not generate the error
message. Also I would never change the section's height in the manner you
are currently using. You have no boundary/error checking in place. Section
Heights, because of CanGrow situations across a page boundary, are not
always what you think they are.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
R

Rob Parker

Stephen,

If I set the image control's Visible property to No, and don't resize
it, I'm back to my original problem situation - the report contains
white space where the image control is located.

My detail section contains only two textboxes and the image control (as
I said in my initial post); all are placed below one another, so there
is nothing else preventing the Detail section from shrinking, yet it
only does so to accommodate changes in the textbox contents.

It seems to me, therefore, that I must resize both the image control
and the section. What boundary/error checking do I need to cope with
the CanGrow across a page boundary? Or is there another way to get rid
of the unwanted white space when there is no image?

Rob
 
S

Stephen Lebans

Sorry you misunderstood Rob. I mean to set the Image control's Visible prop
to No and resize the Detail section.

In CanGrow situations, across two pages, the Detail section may not be the
height you expect, nor the two Textbox controls. What I am suggesting is
that you always check and use the current height for the Section and the
TextBox controls and derive your calculations from that ensuring that you do
not calculate a negative value.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
R

Rob Parker

I think I understand what you're saying, but I'm having trouble getting
it to work.

I've also been fiddling with a similar problem, using a vertical line
(Top = 0) to set a border for the detail section of another report.
What works for me there is:
Detail_Format event:
linLeft.Visible = False
linLeft.Height = Me.Section(acDetail).Height
Detail_Print event:
linLeft.Visible = True

Works like a charm!

But doing what seems to be essentially the same thing for my image
control does not work:
Detail_Format event:
imgImage.Visible = False
imgImage.Height = 0 or 8*567, depending on wherever image exists
Detail_Print event:
linLeft.Visible = True

The Detail section in this case does not resize - it always is large
enough for the image, and it contains white space if no image.
Changing the initial size of the image control in the report's design
mode also has no effect. One more thing, which I've just found: the
image control/detail section will be shrunk until a record is processed
with an image; once that is done, the image control will always need
the image height. Now that, to me, is weird.

I'm about to leave work for today; however, I could send you a small
..mdb file containing my problem later tonight from home, if that would
help - and if you've got time to spare to look at it ;-)

Rob
 
S

Stephen Lebans

Rob I spent the weekend working on the new version of my ReportToPDF
converter. The rest of my free programming time this week is booked. If you
can wait send me the MDB at the end of this week and I'll take a look at it
for you.

I would note that I have seen a lot of problems with making controls Visible
in the Print event. Section Heights should be set in stone by the time of
the Print event.

To render a border in the Detail section that works in CanGrow/Shrink
situations, use the Line method of the Report object. There is code on my
site showing you how to do this.

Finally, your code below is missing the call to actually resize the Detail
section itself(after you set the Visible prop of your Image control). Leave
the Print event out of this and only use the Format event.
--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
R

Rob Parker

Thanks for the offer Stephen,

If I'm still struggling by next weekend, I'll contact you directly via the
feedback facility on your website.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top