Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Closing and Opening Forms Question

Status
Not open for further replies.

metrodub

Technical User
Dec 29, 2004
82
US
I have a form (Class) that can be opened from two different locations. The first is from a search form that is a pop-up form opened from my startup form. The second is from a Work form.

On the Class form is a close form button. What I'd like to happen is if the user opened the Class form from the Work form and clicks the close form button they are sent back to the Work Form. If the user opened the Class form from the search form, then upon pressing the close form button they would be returned to either the search form or the Work form (preferable).

How can I code Access to recognize which form was the jumpoff point?
 
Just noticed a typo.

If the user opens the Class form from the search form and presses the close form button, they would be sent back to the search form or the STARTUP form (preferable). <--not Work form as stated above.
 
If you are not using OpenArgs for anything else, then you could use that to pass the name of the calling form.

Hope this helps.
 
I too, use OpenArgs all the time for this, passing in the name of the calling form. (By the way use Me.Name and not the name of the form in Quotes when you pass it)


under the close button in the CALLED form, put something like this.

If IsNull(Me.OpenArgs) Then
MsgBox "OpenArgs is NULL! Fix This!", vbExclamation
Else
if isopen (me.openargs) then 'I have an IsOpen Func
Forms(Me.OpenArgs).Visible = True
else
docmd.openform me.openargs
endif
End If
 
Thanks for both of the replies. Worked flawlessly (so far). What factors are there for using Me.Name instead of the form name in quotes?
 
In the calling form do:

DoCmd.OpenForm "frmSecondForm",,,stLinkCriteria,,,Me.Name

instead of:

DoCmd.OpenForm "frmSecondForm",,,stLinkCriteria,,,"frmFirstForm"

Will save time and frustration down the road (i.e., when you copy the form and re-use it in some other manner, giving it a new name. That would break the second line of code while the first will still work.
No biggie, just better practice.
Rob
 
In one program I have a hierarchy of forms which, under various circumstances can be opened from any number of different forms. Additionally the program requires a logical path back from whatever form is currently displayed through the various layers of forms to the application's main form. To achieve this, I use a "form stack", providing push, pop and peek functionality. At one or two points in the program it is also necessary to open a form and to change that form's position in the hierarchy, for which I provide an insert routine.

Based on your original question, I think OpenArgs would be sufficient - however if it is more complex, then something along the lines of a stack can come in very useful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top