I am trying to do some of my own error trapping, but I'm not exactly sure how to do it correctly. I have a form where a user can enter information and add it to a table. I am just trying to make the form more robust, so when a user types something, but hits the close button, it will ask the user if he wants to close the form without saving or not. So far this part works fine.
I'm running into a problem where the user says "no, I hit the close button on accident, I want to return to the form just as it is." I can't get access to stop closing the form. Any ideas? Here is some of my code:
Private Sub Form_Error(DataError As Integer, Response as Integer)
Dim UserResponse as Integer
'Error where a required field is not filled out
If (DataErr = 3314) Then
If (FormClean = False) Then 'FORM IS DIRTY
UserResponse = MsgBox ("Close form?", vbYesNoCancel)
If (UserResponse=Yes) Then
Me.Undo
Response = acDataErrContinue
keepopen=false
Else
'Stop closing form and return to normal state
Response = acDataErrContinue
keepopen=true
End If
Else 'FORM IS CLEAN
Response = acDataErrContinue
End If
ElseIf (DataErr = 2169)
'This error says Access encountered an error
'while trying to save a record. Error message asks
'if I still want to close the database object?
'I am trying to answer it with yes or no.
Const ResponseNo as Integer = 7
Const ResponseYes as Integer = 6
If (keepopen = false) Then
msgbox ("Keep the form open!!"
Response=ResponseNo
Else
msgbox ("Close the form!!!"
Response=ResponseYes
End
End If
The error message for 2169 gives me a yes or no option. I am trying to figure out a way I can pre-select the answer for the user. On MSDN, it says you can have Response be acDataErrContinue, (where it surpresses the error message and continues), acDataErrDisplay (where it shows the error message) or a constant. I'm trying to use constants 6 and 7 for yes and no, respectively.
Am I anywhere near the right track or am I just treading water? Any help would be appreciated. Thanks!!!!!!!
I'm running into a problem where the user says "no, I hit the close button on accident, I want to return to the form just as it is." I can't get access to stop closing the form. Any ideas? Here is some of my code:
Private Sub Form_Error(DataError As Integer, Response as Integer)
Dim UserResponse as Integer
'Error where a required field is not filled out
If (DataErr = 3314) Then
If (FormClean = False) Then 'FORM IS DIRTY
UserResponse = MsgBox ("Close form?", vbYesNoCancel)
If (UserResponse=Yes) Then
Me.Undo
Response = acDataErrContinue
keepopen=false
Else
'Stop closing form and return to normal state
Response = acDataErrContinue
keepopen=true
End If
Else 'FORM IS CLEAN
Response = acDataErrContinue
End If
ElseIf (DataErr = 2169)
'This error says Access encountered an error
'while trying to save a record. Error message asks
'if I still want to close the database object?
'I am trying to answer it with yes or no.
Const ResponseNo as Integer = 7
Const ResponseYes as Integer = 6
If (keepopen = false) Then
msgbox ("Keep the form open!!"
Response=ResponseNo
Else
msgbox ("Close the form!!!"
Response=ResponseYes
End
End If
The error message for 2169 gives me a yes or no option. I am trying to figure out a way I can pre-select the answer for the user. On MSDN, it says you can have Response be acDataErrContinue, (where it surpresses the error message and continues), acDataErrDisplay (where it shows the error message) or a constant. I'm trying to use constants 6 and 7 for yes and no, respectively.
Am I anywhere near the right track or am I just treading water? Any help would be appreciated. Thanks!!!!!!!