Reference a Routine on a Subform

  • Thread starter Surveyor In VA via AccessMonster.com
  • Start date
S

Surveyor In VA via AccessMonster.com

Hello

I have a form called "Form1" who has a subform called "subform1". Depending
on what the user picks as the source object, subform 1 can be either 1.)
frmCalendar, 2.) frmContacts or 3.) frmProjects.

On each one of these forms (frmCalendar, frmContacts, and frmProjects) I have
a routine called Public Sub RefreshForm ()
This routine turns on a progress bar, runs a different function depending on
the form.

I have created a button on Form1 that I would like to call this routine. I
have created the following code on the On_Click Event
Dim txtModule1 as String
'Sets the form to open
txtModule1 = Me.Subform1.SourceObject
Set MySubform = Forms(txtModule1)

'Call refresh
Call MySubform.RefreshForm

When I click the button an error comes up saying that "frmCalendar" can not
be found, but I took the name directly from the SourceObject for the subform.
Is there something else that I should be doing?

Regards,
Chris F.
 
M

Marshall Barton

Surveyor said:
I have a form called "Form1" who has a subform called "subform1". Depending
on what the user picks as the source object, subform 1 can be either 1.)
frmCalendar, 2.) frmContacts or 3.) frmProjects.

On each one of these forms (frmCalendar, frmContacts, and frmProjects) I have
a routine called Public Sub RefreshForm ()
This routine turns on a progress bar, runs a different function depending on
the form.

I have created a button on Form1 that I would like to call this routine. I
have created the following code on the On_Click Event
Dim txtModule1 as String
'Sets the form to open
txtModule1 = Me.Subform1.SourceObject
Set MySubform = Forms(txtModule1)

'Call refresh
Call MySubform.RefreshForm

When I click the button an error comes up saying that "frmCalendar" can not
be found, but I took the name directly from the SourceObject for the subform.
Is there something else that I should be doing?


Properties (including controls and fields) and methods
(including event and other procedures) on a subform are
references through the containing subform control, not the
form object it is displaying.

Replace all of your button's code with:

Me.subform1.Form.RefreshForm
 

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