I think the easiest way to do that is to use a function in both the calling form and the called form.
Form A has a function that looks like this:
private frmCalledFrom as Form
public sub SetForm (Calling as Form)
set frmCalledFrom = Calling
end sub
Assuming your calling form uses a button to call, in the OnClick event, put this code (after the form has been opened):
Forms![Form A].SetForm Me
Now, when you want to reference the calling form, you can do so by using the frmCalledFrom object. To get the name, you'd use: frmCalledFrom.Name
Let me know if that doesn't help.
I often? sometimes? just keep a "stack" of the forms 'visited'. In a 'general' module, declare an undiminsioned array of strings to hold the form names.
Eaach event which opens a new form simply "pushes" the form name onto the "stack" by incrementing the array bound and adding te form name to the arrar in the 'last' position. When a form return you may "pop" the name off of the stack. In a variation, I created the array as a UDT with additional "items" to pass to the 'new' form, but this is really not usually necessary. In your scenario, you could always 'know' where "FormA" was instantiated just buy inspection of the stack.
This works quite well for small to moderate sized apps, but might cause some minor performance degradation for larger ones, the largest nuumber of items I have ever actually seen on the "stack" was about 40, and this imposed no discernable performance penalty.
MichaelRed
redmsp@erols.com
There is never time to do it right but there is always time to do it over
If you know you will have a very linear progression of forms, MichaelRed's suggestion will work, but here is a scenario where it doesn't work:
Open Form A
Open Form B from Form A
Open Form C from Form A (without closing Form B)
The stack now holds Form A
Form B
Form C
suggesting that Form C was opened from Form A
Also, if you want to know what form called Form B, you can't just look at the end of the stack - 1, you have to do a search for Form B.
In the code I gave you above, you just use frmCalledFrom within Form B to find the calling form. Also, I don't know why you want the name of the calling form, but I'd guess you want to do something with it, hide it, show it, close it, whatever. That would indicate you're not really looking for the form name, but for a pointer to the form, which frmCalledFrom gives you.
No offense intended. I was only trying to point out the usefulness of a pointer to a form, rather than a form name. Now that I think about it, the array you mentioned could easily include the pointer rather than the form name.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.