How to find out which form spawned another form

  • Thread starter Thread starter Joey
  • Start date Start date
J

Joey

Hello all,

I would like to use one form with differing functionality depending on
which form opened the form. For instance FORMX will behave differently
if opened by FORMA than if FORMX is opened with FORMB. It is possible
that FORMA and FORMB may both be open already. I cannot use the
OpenArgs argument of the OpenForm because the forms are not bound to any
records. How can I acheive this or how can I determine which form
spawned another form?

Thanks,
Joey.
 
I can't see why OpenArgs doesn't work when the Forms are unbound. After
all, OpenArgs is simply a String you pass from the calling code (OpenForm)
to the Form being opened. It has nothing to do with whether the Form is
bound or not.
 
I do this all the time, you can go:

At the forms MODULE level, you define a variable that all the code in the
form can use that refers to the CALLING form.

You can go:

Option Compare Database
Option Explicit

dim frmPrev as form ' ref to calling form.

Now, in the on-open event you go:

set frmPrev = screen.ActiveForm

What most interesting here is that you can even put the above code in the
on-load event (that is quite late in the forms loading process, but yet it
is STILL before the form becomes active.

Now, anywhere in code, you can use the previous form

frmPrev!LastName = "hello"

Or, you can force a disk write in the previous form

frmPrev.Refresh

Or, you can requery the form
frmPrev.Requery

Or, even use code, and custom methods to pass/return values

frmPrev.MyCustomGoToid = 124

The above would make the previous for go to record 124 (assuming you have a
custom property you added to the form).

So, just pick up the ActiveForm in the on-open, or even as mentioned as LATE
as the forms on-load event.
 
Back
Top