I have been having problems with the following code. I have one form with two buttons on it: "undo_record" button and an "exit" button. On this form I have code set up in the Unload event to check if certain fields contain a value, before the user can close out of the form. This is the code I have for the missing field verification:
Dim strMsg As String, strTitle As String
strMsg = "Please enter a "
strTitle = " Missing Entry"
If me.Dirty Then
If IsNull(Me![Reason for Modification]) Then
MsgBox strMsg & "Reason for Modification", vbInformation + vbOKOnly, strTitle
Me![Reason for Modification].SetFocus
Cancel = True
End If
If IsNull(Me![txtEquipmentID]) Then
MsgBox strMsg & "Equipment ID", vbInformation + vbOKOnly, strTitle
Me![txtEquipmentID].SetFocus
Cancel = True
End If
If IsNull(Me![Position]) Then
MsgBox strMsg & "Position", vbInformation + vbOKOnly, strTitle
Me![Position].SetFocus
Cancel = True
End If
End If
End Sub
This is the code I have to undo the record and exit the form:
Private Sub undo_record_Click()
Dim strMsg As String, strTitle As String
Dim intResponse As Integer
strMsg = "You Chose to Cancel This Entry." & vbNewLine & vbNewLine & _
" Are You Sure?"
strTitle = "Are You Sure?"
intResponse = MsgBox(strMsg, vbQuestion + vbYesNo, strTitle)
If intResponse = vbYes Then
Me.Undo
DoCmd.Close
End If
End Sub
With what I have, one button works and other doesn't. The "undo_record" button works great. It close the form without saving the record to the table. But if a user is filling in the form and leaves a field blank, and hits the "exit button" the the form closes without checking for the null fields! I've tried everything, but can't figure out why the field validation code won't fire!! Any suggestions?
Dim strMsg As String, strTitle As String
strMsg = "Please enter a "
strTitle = " Missing Entry"
If me.Dirty Then
If IsNull(Me![Reason for Modification]) Then
MsgBox strMsg & "Reason for Modification", vbInformation + vbOKOnly, strTitle
Me![Reason for Modification].SetFocus
Cancel = True
End If
If IsNull(Me![txtEquipmentID]) Then
MsgBox strMsg & "Equipment ID", vbInformation + vbOKOnly, strTitle
Me![txtEquipmentID].SetFocus
Cancel = True
End If
If IsNull(Me![Position]) Then
MsgBox strMsg & "Position", vbInformation + vbOKOnly, strTitle
Me![Position].SetFocus
Cancel = True
End If
End If
End Sub
This is the code I have to undo the record and exit the form:
Private Sub undo_record_Click()
Dim strMsg As String, strTitle As String
Dim intResponse As Integer
strMsg = "You Chose to Cancel This Entry." & vbNewLine & vbNewLine & _
" Are You Sure?"
strTitle = "Are You Sure?"
intResponse = MsgBox(strMsg, vbQuestion + vbYesNo, strTitle)
If intResponse = vbYes Then
Me.Undo
DoCmd.Close
End If
End Sub
With what I have, one button works and other doesn't. The "undo_record" button works great. It close the form without saving the record to the table. But if a user is filling in the form and leaves a field blank, and hits the "exit button" the the form closes without checking for the null fields! I've tried everything, but can't figure out why the field validation code won't fire!! Any suggestions?