MsgBox Closing main form then the correct form?

applevacross

Registered User.
Local time
Today, 04:08
Joined
Jul 15, 2005
Messages
17
Hi all,

I've added a message box to what is basically a standard simple to use access control, "closeForm", I'm a newbie working on learning access vb. I'm guessing my code if fudged. Any help is greatly appreciated.

Private Sub Close_Click()
On Error GoTo Err_Close_Click
Dim Answer As Integer
Answer = MsgBox("Press Ok to Close, Cancel to Continue.", vbOKCancel + vbQuestion, "Exit Data Entry?")
If vbOK Then DoCmd.Close

Exit_Close_Click:
Exit Sub

Err_Close_Click:
MsgBox Err.Description
Resume Exit_Close_Click

End Sub


Thanks to all in advance
 
Try this:

Private Sub Close_Click()
If MsgBox("Press Ok to Close, Cancel to Continue ", vbOKCancel, "Exit Data Entry") = vbOK Then
DoCmd.Close
End If
End Sub
 
Thanks for your reply! Well, something real wierd is happening. Cancel works perfectly, however, when I click Ok, the mainform closes, not the existing dataentry form. I click the button again>Select ok again, then the dataentry form does close. Am I somehow bound to both? Thank you for your reply!
 
DoCmd.Close acForm, "Your Form Name"
 
Code:
DoCmd.Close acForm, Me.Name [COLOR=SeaGreen]'will close the form that called the code[/COLOR]
 
Excellent, Perfect. Thanks much. I'm learning from those who know!
 

Users who are viewing this thread

Back
Top Bottom