VBA code to close form

harleyskater

IT Manager
Local time
Today, 11:59
Joined
Oct 29, 2007
Messages
95
I have a form with a command button. I just want it to close the form.
Any quick code?
 
Try the command button wizard, which will use the Close command in VBA.
 
it decided to use a macro : ) is there a way to have a macro and a vba code assigned to one command button?

Try the command button wizard, which will use the Close command in VBA.
 
or if you want to do it yourself simlpy type:

Code:
Me.Close

Code:
If you want to quit the entire access application then i believe the code is:

Application.Quit

Its always advisible to throw up a message box to the user incase they have pressed the button by accident. So you'll need something like:

Code:
Private Sub YOURBUTTON_Click()
Dim x as Integer

x = MsgBox("Are you sure you want to quit?", 4, "Exit?")

'VbNo constant throws back #7
'VbYes constant throws back #6

If x = 7 Then
Exit Sub
Else
Application.Quit
'Or Me.Close
End If

End Sub
 
I forgot the wizards make embedded macros now. You can't have both, so I'd get rid of the embedded macro and put in code instead. That way, you can add whatever else you wanted.
 

Users who are viewing this thread

Back
Top Bottom