Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If statment and yes no message box - Confused

Status
Not open for further replies.

Moss100

Technical User
Aug 10, 2004
584
GB
Hello I have the code below (I am a bit confused by the If statements and YES NO message box.

I want to use the code to check if the form is dirty (it references a check box that is set when the form is dirty)
If dirty a message box pops up saving "do you want to save changes..." - if the user chooses Yes then the form
will close and if the user chooses NO the me.undo command will run and then the form will close.

Is my logic OK here?

I would appreciate someone looking at the code as I realise something is wrong as I have 2 Ifs - but not quite sure what to do!

Code:
If Me.txt_dirty = True Then

DoCmd.SetWarnings False

If MsgBox("prompt", vbYesNo, "Do you want to SAVE CHANGES?") = vbYes Then
DoCmd.Close acForm, "frm_tab_member", acSaveNo
MsgBox "Changes SAVED", , "Status"
 
Else
 
Me.Undo
DoCmd.Close acForm, "frm_tab_member", acSaveNo
MsgBox "Changes NOT SAVED", , "Status"
 
End If
DoCmd.SetWarnings True
End If


Thanks Mark

 
Do yourself a favor: indent your code
Code:
If Me.txt_dirty = True Then
    DoCmd.SetWarnings False
    If MsgBox("prompt", vbYesNo, "Do you want to SAVE CHANGES?") = vbYes Then
        DoCmd.Close acForm, "frm_tab_member", acSaveNo
        MsgBox "Changes SAVED", , "Status"
    Else
        Me.Undo
        DoCmd.Close acForm, "frm_tab_member", acSaveNo
        MsgBox "Changes NOT SAVED", , "Status"
    End If
    DoCmd.SetWarnings True
End If

Now, you better see that your logic seems OK.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top