Sub report VBA not firing when loaded through main report (1 Viewer)

Juett

Registered User.
Local time
Today, 06:18
Joined
Jul 16, 2019
Messages
71
Hi Guys,

I have a little issue with some VBA code in a sub report.

The following code works in the sub report when opened directly:

Code:
Private Sub Report_Load()
If IsNull(cmb1.Value) Then
    Me.img1.Visible = False
Else
    Me.img1.Visible = True
End If
End Sub

It displays or hides an image based on the value of a combo box.

But...when I insert this report as a sub report in another (main form) and open it, the code does not fire.

What do you think I might be missing?

Thanks very much.
 
reports event don't fire when inserted as subreport.
set it on the main reports load event:

private sub report_load()
me.subreportname!img1.Visible = (IsNull(me.subreportname!cmb1)=False)
end sub
 
That worked perfectly, thanks very much!
 
you are welcome!
 
This helped me today.
I needed to resize subform controls, and subform's Report_Open is too soon - the data is not yet available. Report_Load does not fire.
Moved the logic to parent form's Report_Load and all is happy.
 
Folks need to remember that sub-forms load before parent forms. If you do something in the sub-form that depends on something on the parent form, those events have not fired yet, which on initial load would include main-form controls and the Forum_Current event (where data gets loaded).


The relevant section is near the bottom of that rather long - but very useful - page.
 
Folks need to remember that sub-forms load before parent forms.
If you don't like this design-time behavior you can load your subforms/subreports programmatically.
• Delete the name of the form you want to load from the Subform.SourceObject property in design view.
• After the main form opens--and even on a timer if you want more delay--do...
Code:
Me.MySubformControl.SourceObject = "fNameOfSubformToLoad"
This also makes your main form open faster, because no subform queries run until the main form is presented.
 

Users who are viewing this thread

Back
Top Bottom