Labels in group headers question

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a report in which there is a bound control (ID) in the group header. I
have put a label in the same section and want it to display text based on the
number in the ID control. I have tried the following and it won't work. I am
not sure at what point in the report loading I would place it either (if you
are able to do this in reports).

Private Sub Report_Activate()
srtNum = Me.ID

If strNum = 3 Then
lblBudgetText.Caption = " This is label 3"
End If

If strNum = 4 Then
lblBudgetText.Caption = "This is label 4"
End If

End Sub

Any help would be appreciated.
 
I have a report in which there is a bound control (ID) in the group header. I
have put a label in the same section and want it to display text based on the
number in the ID control. I have tried the following and it won't work. I am
not sure at what point in the report loading I would place it either (if you
are able to do this in reports).

Private Sub Report_Activate()
srtNum = Me.ID

If strNum = 3 Then
lblBudgetText.Caption = " This is label 3"
End If

If strNum = 4 Then
lblBudgetText.Caption = "This is label 4"
End If

End Sub

Any help would be appreciated.

There are a couple of problems with your approach.

1) The Report Activate event only fires when the report is previewed,
not when it's printed.

2) The Activate event would only read the value of the very first
record and not any additional ones.

3) Place your code in the Format event of the Group Header.

Me![lblBudgetText].Caption = " This is label " & Me![ID]

No need to create a variable to read the ID value as long as that same
value is to be used in the caption.
The Label caption will change as the ID changes.

4) An easier solution would be to change the label to an unbound text
control. As it's control source, write:
="This is Label " & Me![ID]
No VBA code is required.
 
Back
Top