Error on form exit

  • Thread starter Thread starter George Papadopoulos
  • Start date Start date
G

George Papadopoulos

Hello Access community

I have this problem. I have built a form with text boxes bounded to
records on a table. A user can input data on the form and then press a check
mark button to commit them to the database. I can handle unexpected
conditions, lime a miscomplete form, from the event handler of the check
mark button. Unfortunately if the user presses the close button of the form,
Access tries to commit the miscomplete form to the database and fails.
How can I overcome this problem?

thx, in advance

George Papadopoulos
Electronic Engineer
 
Disable the X button on the form or . . . . . .
If this is a genuine button to exit the form without making any changes -
try something like the following which would be called from the onclick of a
button

Function AbortExitForm()
'Give the user the option to cancel the changes that have been made in the
form
Dim resp

On Error GoTo errorhandling
resp = MsgBox("Do you really want to abort this record entry", vbYesNo)
If resp = vbYes Then

If Forms!frmRecord.Dirty Then
DoCmd.RunCommand acCmdUndo
End If

DoCmd.Close
Else
DoCmd.GoToControl "btnSave"
End If

sExit:
Exit Function

errorhandling:
Select Case Err.Number
Case Else
MsgBox "The follwing error has occurred" & vbCrLf & _
"Error No. " & Err.Number & vbCrLf & _
"Desc: " & Err.Description & vbCrLf & _
"Please contact the Systems Administrator with these details."
End Select
Resume sExit
End Function


HTH
 
Back
Top