Open a form/close current form

jeo

Registered User.
Local time
Today, 14:53
Joined
Dec 26, 2002
Messages
299
On all of my forms I want to put a button - back to Main menu. With this, I want to open the main menu form(which I know how to do that) and close current form (which I don't know how to do).
Could someone please help me.
Thanks!
 
DoCmd.Close acForm, Me.Form.Name

to close your current active form
 
I get an errr/msgbox when my main form comes up that says:
application-defined or object-definer error.
 
for the On-Click event for that button:
Private Sub Command53_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmMain"
DoCmd.OpenForm stDocName, , , stLinkCriteria
DoCmd.Close acForm, Me.Form.frmAddNewClient

End Sub
 
you can do it more general by placing the following code:

Private Sub Command53_Click()
Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "frmMain"
DoCmd.Close acForm, Me.Form.Name
DoCmd.OpenForm stDocName, , , stLinkCriteria
End Sub

Place the above code on the button in your form, it will close your current form (no matter which one it is that's why Me.Form.Name), and it will open you the main menu form.
 
That worked great, thank you!
 
I find it better to create a constant for each object in my database and always use the constant to refer to the form. I would put this in a standalone module.

i.e.

Code:
Public Const fMenu As String = "frmMenu"
Public Const fAdmin As String = "frmAdmin"
]

Now, I just refer to one of my constants whenever I want something.

i.e.

Code:
DoCmd.Close acForm, fAdmin
DoCmd.OpenForm fMenu

None of this stLinkCriteria, stDocName unnecessary wizard rubbish.

Now, should I ever change the name of a form then I only have to change the code in one place rather than looking for every instance where I've mentioned it.
 
Thank you for suggestion. I've never worked with modules...
I guess I better start, so I will try this.
Thank you again.
 
Code:
DoCmd.Close acForm, Me.Name
That will close the current form for which the code was called from. Then you could use this to close the current form and then open the form of choice.

Code:
DoCmd.Close acForm, Me.Name
DoCmd.OpenForm "frmMain"
 

Users who are viewing this thread

Back
Top Bottom