MsgBox

MdbBeginner

New member
Local time
Today, 13:23
Joined
Sep 4, 2008
Messages
6
hey everybody its my first time playing with message boxes im trying to get a little fancy...anyways i have a yes,no msgbox that i cant get the no to work...any suggestions?

Private Sub SaveBttn_Click()
Dim Response As Integer
Response = MsgBox("Add New Agent?", vbQuestion + vbYesNo)
If Response = vbYes Then
DoCmd.Save
MsgBox "Agent Added Succesfully", vbOKOnly
DoCmd.Close
Else
If Response = vbNo Then
DoCmd.Close , "AddAgtFrm", acSaveNo
End If
End Sub
 
Sorry, but your acSave and acSaveNo have nothing to do with records. It has to do with the design changes on forms/reports.

What you need is this (and you can bypass the Response integer):

Code:
Private Sub SaveBttn_Click()
Dim Response As Integer
   If MsgBox("Add New Agent?", vbQuestion + vbYesNo) = vbYes Then
       If Me.Dirty Then Me.Dirty = False
   Else
       Me.Undo
   End If
       DoCmd.Close acForm, Me.Name, acSaveNo
End Sub
 
And if you don't want the form to close if they say NO then you would use:

Code:
Private Sub SaveBttn_Click()
Dim Response As Integer
   If MsgBox("Add New Agent?", vbQuestion + vbYesNo) = vbYes Then
       If Me.Dirty Then Me.Dirty = False
       DoCmd.Close acForm, Me.Name, acSaveNo
   Else
       Me.Undo
   End If
End Sub
 
Thanks for the response, but i figured it out like this:

Private Sub SaveBttn_Click()
Select Case MsgBox("Add New Agent?", vbQuestion + vbYesNo)
Case vbYes
DoCmd.Save
Case vbNo
Me.Undo
DoCmd.Close
End Select
End Sub

I've never seen the Me.Dirty (what does that do?)
 
Dirty is true whenever a user has edited something in the form, and setting it false forces the data to be saved.

If you've used form, you may have seen the black arrow thingy that turns into a pencil writing icon to indicate that this is record. This is basically the same thing.

HTH.
 
Sweet...thanks...always like to learn something new

Code:
Private Sub SaveBttn_Click()
Select Case MsgBox("Add New Agent?", vbQuestion + vbYesNo)
Case vbYes
DoCmd.Save
Use MsgBox("Agent Added succesfully!", MsgBoxOkOnly)
Case vbNo
Me.Undo
DoCmd.Close
End Select
End Sub

How would i get my msgbox to appear after the record is saved?
 
Sweet...thanks...always like to learn something new

Code:
Private Sub SaveBttn_Click()
Select Case MsgBox("Add New Agent?", vbQuestion + vbYesNo)
Case vbYes
DoCmd.Save
Use MsgBox("Agent Added succesfully!", MsgBoxOkOnly)
Case vbNo
Me.Undo
DoCmd.Close
End Select
End Sub

How would i get my msgbox to appear after the record is saved?
You would put it in the form's After Update event.
 

Users who are viewing this thread

Back
Top Bottom