VBA Problem With Reports (1 Viewer)

Chuxley

New member
Local time
Yesterday, 20:07
Joined
Jun 5, 2018
Messages
4
Need help with 2013 report problem. I've written some very simple code under the On Load event procedure that sets the .Visible property of certain text fields to NO, given a numeric value in a numeric field with standard formatting. The code works when opened by itself, but when I insert the reportas a subreport, with a group of other reports (no relationships involved) the code doesn't work. Has anyone had this experience?
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:07
Joined
Aug 30, 2003
Messages
36,125
What's the code? If it uses a full reference, it would have to be adjusted to refer to the subreport.
 

Chuxley

New member
Local time
Yesterday, 20:07
Joined
Jun 5, 2018
Messages
4
Private Sub Report_Load()
If (CPActivities = 0) Then
CPActivities1.Visible = False
Label13.Visible = False
End If
End Sub
 

pbaldy

Wino Moderator
Staff member
Local time
Yesterday, 20:07
Joined
Aug 30, 2003
Messages
36,125
Presuming all are controls I would try to disambiguate:

Code:
If (Me.CPActivities = 0) Then
  Me.CPActivities1.Visible = False
  Me.Label13.Visible = False
End If

You might also try the format event of the section containing the controls (presumably the detail section).
 

arnelgp

..forever waiting... waiting for jellybean!
Local time
Today, 11:07
Joined
May 7, 2009
Messages
19,243
remove the code from the subreport. Load event if subrep doesn't fire.
Instead, move it to the Main reoort's Load Event:
Code:
Private Sub Report_Load()
With Me.subReportNameHere
   If (!CPActivities = 0) Then
      !CPActivities1.Visible = False
      !Label13.Visible = False
   End If
End With
End Sub
 

Mark_

Longboard on the internet
Local time
Yesterday, 20:07
Joined
Sep 12, 2017
Messages
2,111
I would also make sure I have meaningful control names. Making Label13 visible or not does not help you if you don't remember what label13 is used for. It also becomes ambiguous to YOU if you are using this as a subform from a report which ALSO has a label13.
 

Pat Hartman

Super Moderator
Staff member
Local time
Yesterday, 23:07
Joined
Feb 19, 2002
Messages
43,275
The load events of the report/subreport run once and only once so whatever value appears in the first record controls the entire report. Is that what you want?

If you want this to vary for each detail record, put the code into the detail section's Format event.
 

Users who are viewing this thread

Top Bottom