Repost: Listening for events on subform nested in a tab control

J

Jim Shaw

In Access 2002, how do I code a reference to a sub-form in
a main form from an independent third form. The syntax to
reference a sub-form.control does not work and is not
appropriate for my need. I need the sub form iteself, not
a control on the subform. Here is the full story:

I wish to synchronize a "MyPopUpForm" with custom events
generated in "MyMainForm" and "MySubForm".

MySubForm is nested on a page in a tab control
on "MyMainForm".

"MyPopUpForm" is opened via a control button on
MyMainForm, so I'm sure both MyMainForm and MySubForm are
loaded when MyPopUpForm fires its OnLoad event.

MyMainForm raises event "NewEmp(EmpID)" that MySubForm and
MyPopUpForm successfully handle.

So far, so good with my code. Now for what's not working..

MySubForm raises event CurRec(EffectiveDate).
MyPopUpForm should catch and handle the event by updating
a text box control with the EffectiveDate.

Problem: I keep getting messages at runtime that
MySubForm cannot be found.

Here's my code:
-----------------------------------------------------
On "MySubForm", I have declared a custom event in the
global area:

Public Event CurRec(EffectiveDate)

also I have:

Private Sub Form_Current()
RaiseEvent CurRec(EffectiveDate)
End Sub
--------------------------------------------
In the global area of "myPopUp" form I have:

Dim WithEvents subComp As Form_MySubForm

Then I coded:

Private Sub Form_Load()
Set subComp = Forms!frmEmpMaint!MySubForm
End Sub
-------------------------------------------------

My problem is coding the proper syntax for the "Set
subComp" statement above. Various coding attempts have
all lead to runtime messages that generally say the
subform can't be found.

Does anyone you know know how to code this?
 
J

Jim Shaw

Never mind, I figured it out.

The correct syntax is:
Set subComp = Forms!MyMainForm.MySubForm.Form
It also helps to understand that when VBA wants the "name"
of the subform, they mean the name specified on the
properties sheet in the main form, NOT the name that the
sub form was saved as in the application's object list.

Thanks for your consideration of this problem.
-Jim
 

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