Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can A "Can Shrink" Property Be Coded for an Attachment Data Type Field

Status
Not open for further replies.

Bill6868

Technical User
Mar 20, 2007
96
US
On my report I have an Attachment Data Type table field which contains a .jpg photo. If there is no photo for the record I'd like the report to "shrink" this field so that the following text fields can move up on the report.

The "can shrink" property is not available with the attachment data type property options. Could this be done in some other way or VBA code?

Any suggestions would be much appreciated.
 
I have not used the attachment datatype but some initial thoughts...

The idea that seems easiest to implement is to put the picture in a sub report whose record source only has records that have pictures. Then when there is no picture, there is no record and nothing is displayed.

Alternatively, you could try setting the height of the picture control to 0 or appropriate default height in the section's On Format event based on whether there is data in it.

The first is method may be more intuitive but because it is using a sub-report which is more resource intensive (slower). Obviously do not include the picture field in your record source of the main report if using this method.

 
You can control this yourself pretty easily

Code:
Option Compare Database
Option Explicit
Private mAttachHght As Long
Private mAttachTop As Long
Private mFieldTop As Long
Private mDetailHght As Long

Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'count attachments
If Me.attch.AttachmentCount = 0 Then
  Me.attch.Height = 0
  MoveUp
Else
  Me.attch.Height = mAttachHght
  MoveDown
End If
End Sub

Private Sub Report_Load()
  'save heights and top locations
  mAttachHght = Me.attch.Height
  mAttachTop = Me.attch.Top
  mFieldTop = Me.TextFieldTwo.Top
  mDetailHght = Me.Detail.Height
End Sub

Private Sub MoveUp()
  'Move one or more controls to new location
  'Shrink detail section
  Me.TextFieldTwo.Top = mAttachTop
  'once you move all your controls determine the new height
  'Leave that to you to work, I will hard code. You can basically add the heights of
  'the moved controls and any space in between.
  Me.Detail.Height = Me.TextFieldTwo.Height + 0.25
End Sub
Private Sub MoveDown()
  'Move back to original height
  Me.TextFieldTwo.Top = mFieldTop
  Me.Detail.Height = mDetailHght
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top