Link to home
Start Free TrialLog in
Avatar of Scott Palmer
Scott PalmerFlag for United States of America

asked on

I need to run vba code in a subform from the main form

The main form has a button to find a record.  I have a subform on the main form that has vba code to open a recordset and show a list of records.  I would like that to happen when I click on the button on the main form.

I just need the code to be able to reference the vba in the subform from the main form so it will run.

Main form name: frmMain
Subform name: frmFCDBHeader

The code that needs to be called n the subform is: Public Sub FCDB()

Thanks,
Scott
Avatar of Gustav Brock
Gustav Brock
Flag of Denmark image

If the function is public, you can all it like this:

  Call Me!NameOfSubformControl.Form.FCDB()

/gustav
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Is there some particular reason that you are working with unbound forms?

If the subform were bound, it's Recordsource query could reference a control on the mainform to get selection criteria:

WHERE somefield = Forms!MyForm!somefield

Then in the click event of the button, you would requery the subform.

Me.sfrmName.Requery
Avatar of Scott Palmer

ASKER

Thanks