I have an Access report whose records in the Detail section usually require two lines, but occassionally a message needs to be displayed for a particular record. This message is in the form of a label in the third line, which is made either visible or invisible, depending on a flag within the record. To avoid wasting space, I want to adjust the height of the entry to accommodate the third line only when required. The flag is checked, the label.Visible property set, and the section height adjusted in an On Format event procedure.
At least, that's the theory. In practice, I am having difficulty getting the height adjustment to work. According to Microsoft Learn, the Format eevnt is triggered for each record, and the syntax to adjust the height is Me.Detail.Heigh t, but when I try this each record occupies three lines, the third being generally blank. I have also tried Me.section(acDe tail).Height, whic I saw suggested in an AI answer somewhere, to no avail.
I note that if I type Me.detail.heigh t, VBA corrects it to Me.Detail.heigh t but doesn't capitalise the last word, suggesting that it is not being recognised as valid.
The code I am using in the On Format eevnt proceduer is
At least, that's the theory. In practice, I am having difficulty getting the height adjustment to work. According to Microsoft Learn, the Format eevnt is triggered for each record, and the syntax to adjust the height is Me.Detail.Heigh t, but when I try this each record occupies three lines, the third being generally blank. I have also tried Me.section(acDe tail).Height, whic I saw suggested in an AI answer somewhere, to no avail.
I note that if I type Me.detail.heigh t, VBA corrects it to Me.Detail.heigh t but doesn't capitalise the last word, suggesting that it is not being recognised as valid.
The code I am using in the On Format eevnt proceduer is
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
'
' If the pilgrim withdrew during the event, add an extra line to say so.
'
Dim tpcm As Variant
tpcm = 1440 / 2.54 ' twips per centimetre
On Error GoTo ErrorProc
If [Response] = "W" Then
lblWithdrawalNote.Caption = "NB: " & txtFirst_name & " attended initially, but withdrew during the event."
lblWithdrawalNote.Visible = True
Me.Detail.height = 1.8 * tpcm ' Set section height to 1.8cm for this record only
Else
lblWithdrawalNote.Visible = False
Me.Detail.height = 1.2 * tpcm ' Set section height back to 1.2cm for other records
End If
ByeBye:
Exit Sub
ErrorProc:
MsgBox "Error " & Err.Number & " - " & Err.Description, , "Error closing F52"
Resume ByeBye
End Sub
Comment