Message Boxes, Yes/No-Ok/Cancel Buttons (1 Viewer)

NewfieSarah

Registered User.
Local time
Today, 06:48
Joined
Feb 11, 2005
Messages
193
I am having some problems, I tryed a msgbox with only ok and if I would like to save the record I see now needs to be a yes/no buttons, so I changed the ok to yes/no and it saves the changes no matter what. so i will need a If statement correct, but what do I put in it?? The Same thing is happending with my ok/cancel buttons.
Thanks
 
If Msgbox("Save yes no", vbyesNO, "Save?") = vbYes then
 
Here is a simple Yes/No example...
Code:
    If MsgBox("Do you want to close the database?", vbQuestion + vbYesNo, "Exit Database") = vbYes Then
        DoCmd.RunCommand acCmdExit
    Else
        MsgBox "Function aborted"
    End If
Here is a more advanced Yes/No/Cancel example using a select case statement for a custom Save Record button...
Code:
Private Sub bSave_Click()
On Error GoTo Err_bSave_Click

    Me.tbHidden.SetFocus

    If IsNull(tbFirstName) Or IsNull(tbLastName) Then
        Beep
        MsgBox "All required fields must be completed before you can save a record.", vbCritical, "Invalid Save"
        Exit Sub
    End If

    Beep
    Select Case MsgBox("Do you want to save your changes to the current record?" & vbCrLf & vbLf & "  Yes:         Saves Changes" & vbCrLf & "  No:          Does NOT Save Changes" & vbCrLf & "  Cancel:    Reset (Undo) Changes" & vbCrLf, vbYesNoCancel + vbQuestion, "Save Current Record?")
        Case vbYes: 'Save the changes
            DoCmd.RunCommand acCmdSaveRecord

        Case vbNo: 'Do not save or undo
            'Do nothing

        Case vbCancel: 'Undo the changes
            DoCmd.RunCommand acCmdUndo

        Case Else: 'Default case to trap any errors
            'Do nothing
    End Select

Exit_bSave_Click:
    Exit Sub

Err_bSave_Click:
    If Err = 2046 Then 'The command or action Undo is not available now
        Exit Sub
    Else
        MsgBox Err.Number & " - " & Err.Description
        Resume Exit_bSave_Click
    End If
    
End Sub

Check out these two links For more ideas...

A Better Mouse Trap?

Enable/Disable The Control Box X Button
 
the for the help, I was to use a delete button with the select case what would I use instead of undo. Save and undo make sence, but what if I want to delete, and not delete what would I use then? If I was to use a exit yes and no case what would i use for that. yes exit and no... Thanks
 
You need to think the logic through and make the appropriate action based on the users response [click].

Code:
    If MsgBox("Are you sure you want to delete the current record?", vbQuestion + vbYesNo, "Delete Current Record?") = vbYes Then
        DoCmd.SetWarnings False
        DoCmd.RunCommand acCmdDeleteRecord
        DoCmd.SetWarnings True
    Else
        MsgBox "Delete Aborted"
    End If
 

Users who are viewing this thread

Back
Top Bottom