Auto close form when another opens

jayme27

Registered User.
Local time
Today, 10:12
Joined
Nov 24, 1999
Messages
34
I have many forms in my database, but I don't want the user to have more than the current one open as they navigate through the menus.

Example: The user leaves frmMain (by clicking any one of several macros on that form which take the user elsewhere to another form). When the new form opens, the previous form (frmMain in this case) will close automatically.

Please be specific on what code I need and how to do it or where it goes. I got myself in a mess trying to put a Form CLOSE code in on_focus, on_lost_focus, deactivate, on_activate, and so forth. It didn't do the job. What do you recommend?
 
I suggest that you give your users only one single possibility to access certain forms. Then it is not only quite easy to close the undesired forms but data integrity is easier to control.
On the other hand, for performance and memory-issues it might be more intelligent to keep certain forms open and just change their visible property to false.
As far as makros are concerned: convert them ASAP to VBA.
 
I agree that it is better to do this in VBA. Also, it is sometimes better to leave a form open but invisible.

Let's say you want to go from a menu to a browse screen. The user would click a "Browse" button on the menu, and the VBA code in the button Click event would look like this:
DoCmd.Close acForm, "fBrowse"
[Forms]![fMainMenu].Visible = True
Then, in the fBrowse form, you could have a another button to get you back to the menu. It's Click code goes like this:
' This first code will save changes:
If Me.Dirty Then
If MsgBox("Do you wish to save changes?", vbYesNo + vbQuestion, "SAVE CHANGES?") = vbNo Then
Me.Undo
End If
End If
' Now close the current form and let them see the menu
DoCmd.Close acForm, "fBrowse"
[Forms]![fMainMenu].Visible = True
If you really want to close the menu, the code in the first button Click goes like this:
strFormName = "fBrowse"
DoCmd.OpenForm strDocName
strFormName = "fMainMenu"
DoCmd.Close acForm, strDocName
Then, in the browse screen, you'd do this:
strFormName = "fMainMenu"
DoCmd.OpenForm strDocName
strFormName = "fBrowse"
DoCmd.Close acForm, strDocName
 
Creat a macro that closes one form and opens the next, then open your form in design view and create macro button, then assign the macro to the button. You will have to create a new macro for each button that opens a form.
 
Thanks Andy. I could successfully follow the way you describe. Plus it was the easiest to understand.
 

Users who are viewing this thread

Back
Top Bottom