Okay, here we go. I am really close with only a few weird bugs (more than likely based on syntax, I am sure).
Code:
Private Sub close_btn_Click()
Dim Msg, Style, Title, Response, MyString
Msg = "Changes have been made to this record." + Chr(13) + _
"Do you want to save first?"
Style = vbYesNoCancel + vbExclamation + vbDefaultButton3
Title = "WAIT! Before You Go"
Response = MsgBox(Msg, Style, Title)
If Me.Dirty = True Then
If Response = vbYes Then 'User chooses yes button, so Save the Record
DoCmd.RunCommand acCmdSaveRecord
Else
If Response = vbNo Then 'Otherwise if user chooses No, undo changes
DoCmd.RunCommand acCmdUndo
End If
End If
DoCmd.Close acForm, "tracker_frm" 'Close form after the above choices
Else
DoCmd.Close acForm, "tracker_frm"
End If
End Sub
So, essentially if the record has been changed at all (i.e. Me.Dirty = True) then the user will be prompted with the Message Box telling them that the record has been changed and whether or not they want to save the record (Yes), discard the changes (No), or Cancel.
The function of the Yes and No buttons works well everytime. However, it works whether the record is dirty or not and I cannot figure out why.
So, I also have a couple of onCurrent functions that actually populate a couple of unbound fields with lookup data, shown here:
Code:
Private Sub Form_Current()
' Updates the proper tech name upon navigating through the record set
txt_techName = DLookup("techName", "tech_tbl", "techNum=" & "tech_TechNum")
' Set Focus to W.O. Number upon new record
If Me.NewRecord Then
Me.trkr_woNumber.SetFocus
End If
' Updates the proper FSM name upon navigating through the record set; without
txt_FSM = DLookup("fsm_name", "qryFSM_Tech_Assignments", "techNum=" & "tech_TechNum")
Me.Dirty = False
End Sub
So, before all of this, I did not have Me.Dirty = False at the end of the Sub. Only upon working with this message box did I realize that every record upon loading is technically dirty, right? Because although I did not make any changes, the VBA did, therefore = dirty.
However, this still does not work.
Basically, the message box will pop up under every circumstance. So, if I navigate to a record and make no changes and click the close button, I still get the message box. How can I fix that?
Also, the cancel button click now closes the form as well, which I do not want. I just want it to cancel the message box and go back to the form.
Thanks
Mike