This is in reference to some of my previous post, but different, so here I am posting something new! I have a form set up so that the user has to fill in fields before they can exit the form. I have this in the unload event and it worked great until something was brought to my attention. "What if the user accidently opens the form and doesn't want to fill anything in?".... So I decided to put a cancel button on 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
Then if the user clicked on the "undo_record" button, the code from the unload event would prompt the user to fill in the blanks that were missing and wouldn't let you exit out of the form. And So then I manipulated the Unload event and added this at the beginning of my IF statements and changed the other IF's to ElseIF's:
If Me.undo_record.Enabled = True Then
Me.Undo
Exit Sub
I thought this did the trick! If you click the "undo_record" then it closes out of the form nicely, not saving any info. But if you go and start to fill in the form and think you have it filled and click the "exit" button, and one of your fields is blank, then the form closes without prompting the user to fill them in and saves the record. I'm confused on where to go now. I know there is something wrong with the Unload event, but have no ideas. Any suggestions?
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
Then if the user clicked on the "undo_record" button, the code from the unload event would prompt the user to fill in the blanks that were missing and wouldn't let you exit out of the form. And So then I manipulated the Unload event and added this at the beginning of my IF statements and changed the other IF's to ElseIF's:
If Me.undo_record.Enabled = True Then
Me.Undo
Exit Sub
I thought this did the trick! If you click the "undo_record" then it closes out of the form nicely, not saving any info. But if you go and start to fill in the form and think you have it filled and click the "exit" button, and one of your fields is blank, then the form closes without prompting the user to fill them in and saves the record. I'm confused on where to go now. I know there is something wrong with the Unload event, but have no ideas. Any suggestions?