Call a subform function from the form?

M

Max Moor

Hi All,

I need to update a couple of text boxes on a subform after a combobox
on the main form is changed. What is the syntax for calling a function in a
subform module from the module for the mainform?

Thanks, Max
 
A

Allen Browne

Remove the Private keyword from the Sub declaration line in the subform's
module.

If the subform is name Sub1, and the procedure is named Text0_AfterUpdate,
you can then call it like this:
Call Form_Sub1.Text0_AfterUpdate

An alternative approach would be to move the procedure into a standard
module. You can pass a reference to the form like this:
Function DoSomething(frm As Form)
and use frm anywhere you used Me in the subform's module.
To call it from the main form's module:
Call DoSomething([Sub1].Form)
To call it from the subform's module:
Call DoSomething(Me)
 
M

Max Moor

Remove the Private keyword from the Sub declaration line in the subform's
module.

If the subform is name Sub1, and the procedure is named Text0_AfterUpdate,
you can then call it like this:
Call Form_Sub1.Text0_AfterUpdate

I forgot about the Private keyword. I was staring right at it, and didn't
see it. Thanks Allen.

- Max
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top