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
Scott PalmerData AnalystAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Rey Obrero (Capricorn1)Connect With a Mentor Commented:
in the click event of the button place this codes

Private Sub btnName_Click()

Form_frmFCDBHeader.FCDB

end sub
0
 
Gustav BrockCIOCommented:
If the function is public, you can all it like this:

  Call Me!NameOfSubformControl.Form.FCDB()

/gustav
0
 
PatHartmanCommented:
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
0
 
Scott PalmerData AnalystAuthor Commented:
Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.