Identify which form opened form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have 2 forms (A & B) which both have a button to open another form (C). Is
there a way to identify which form (A or B) was used to open it the other
form (C)?

Thank you,

Daniel
 
Daniel said:
I have 2 forms (A & B) which both have a button to open another form
(C). Is there a way to identify which form (A or B) was used to open
it the other form (C)?

Thank you,

Daniel

Depends on when and where you want to do it. You can have the "calling
form" (form A or B) pass its name to the "called form" (form C) via the
OpenArgs parameter of the DoCmd.OpenForm method. Or you can get the
value of Screen.ActiveForm.Name in the Open event of form C -- at this
point, C is not yet active, so the form that was active at the moment it
was opened (presumably form A or form B) will be returned by
Screen.ActiveForm. This latter method could potentially fail if some
other form grabs the focus (possibly due to a Timer event) at the moment
you open form C, but I've never seen that actually happen.
 
Thank you Dirk,

Once again you saved me an enormous amount of time and frustration.... with
an easy solution!

Daniel
 
Daniel,

If you change the way you think about opening forms you can do it reliably.

Instead of using Docmd you set a module level variable code page for the
'parent' form of the type of the child form. Say the child form is called
frmChildForm this would look like the following;

Private frmChildForm As Form_frmChildForm

Where you would use Docmd you can now use;

Set frmChildForm=New Form_frmChildForm
frmChildForm.Show

This is actually opening an instance of the form rather than the form itself.

To get a link back to the parent you need to add some more code however. In
the child forms code module;

Private frmParentForm As Form

Public Property Get ParentForm() As Form

Set ParentForm = frmParentForm

End Property

Public Property Set ParentForm(frmNewValue As Form)

Set frmParentForm = frmNewValue

End Property

To establish a link between parent & child you would need to change the code
mentioned before on the parent form;

Set frmChildForm=New Form_frmChildForm
Set frmChildForm.ParentForm=Me
frmChildForm.Show

You can now access all properties/methods/controls on the parent form from
the child form reliably & 'know' who your parent is. To close the child form
you actually end up creating a method on the parent that you call from the
child ... it is quite different but a lot more powerful than Docmd (in my
opinion).

I think I have a toy solution using his knocking about if you are interested
- dig my email out of my details & drop me a line.

Regards,

Chris.
 
Back
Top