Surfing between forms (1 Viewer)

Massoud

Registered User.
Local time
Today, 00:31
Joined
Jul 11, 2002
Messages
37
Hi all,

In my access program I need to surf between various forms, back and forth.

To open a form I usually use the docmd.openform .... way. This works, but doesn't close the previous form. What I need is a way that every time, only one form is open so we are not confused. Also a particular form may be opened from different forms and when closing it, we should get back to that form which had called for it.
What should be my strategy?

Thanks again in advance.
 

wazz

Super Moderator
Local time
Today, 07:31
Joined
Jun 29, 2004
Messages
1,711
there are many ways to do this. docmd. is fine. what you can do is make the first form invisible:
Me.Visible = False
- open the next form. tell the next form who is calling it (Me.Name) by adding the name of the current form to the OpenArgs argument:
DoCmd.OpenForm "frmName",,,,,,Me.Name
- close the opened form and make the calling form visible again. in the called form's close event:
If Me.OpenArgs & "" <> "" then
Forms(Me.OpenArgs).Visible = True
End If
 

Massoud

Registered User.
Local time
Today, 00:31
Joined
Jul 11, 2002
Messages
37
Thanks wazz.
but to keep the track of forms from the beginning I used a public variable as string and in it i stored the names of the forms in the LIFO (Last in first out) way. This way I can always get throug my steps back to the main form.
Any idea?
Thanks again.
 

Libre

been around a little
Local time
Yesterday, 16:31
Joined
May 3, 2007
Messages
660
This should do it.
On the launch button to open a form you save the name of the form you're starting from as a public variable (myForm) as you've done:

Put this under the CLOSE button on each form.

Dim sFrmName as String

For Each AccessObject In CurrentProject.AllForms
sFrmName = AccessObject.Name
If CurrentProject.AllForms(sFrmName).IsLoaded Then
DoCmd.Close acForm, sFrmName, acSaveNo
End If
Next
(that will close all open forms in the project)

DoCmd.OpenForm myForm

Note: You have to eliminate the control box on the forms to stop people from sidestepping your CLOSE button and instead clicking on the "X" in the control box.
 

Users who are viewing this thread

Top Bottom