I have a situation where users add one field and then close the form leaving imcomplete records in the table. I tried similar coding in the Before_update and got a similar result. I may be way off on this but here is what I have, (at this point I get an error and the form closes anyway):
Private Sub Form_Close()
On Error GoTo ErrorHandler
' Stop User from leaving empty fields.
If Len(Me.Name & vbNullString) > 0 Then
' Go back to form to finish filling it out.
If MsgBox("If you close without saving, all data will be lost. Do you want to close anyway?", vbYesNo, "Data Missing...") = vbNo Then
Cancel = True
Me.SetFocus
' Clear Fields and close the form
Else
Cancel = False
Me.Undo
Resume ExitProcedure
End If
End If
ExitProcedure:
Exit Sub
ErrorHandler:
If Err.Number > 0 Then
MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
Resume ExitProcedure
End Sub
Thanks for any help you can give.
Private Sub Form_Close()
On Error GoTo ErrorHandler
' Stop User from leaving empty fields.
If Len(Me.Name & vbNullString) > 0 Then
' Go back to form to finish filling it out.
If MsgBox("If you close without saving, all data will be lost. Do you want to close anyway?", vbYesNo, "Data Missing...") = vbNo Then
Cancel = True
Me.SetFocus
' Clear Fields and close the form
Else
Cancel = False
Me.Undo
Resume ExitProcedure
End If
End If
ExitProcedure:
Exit Sub
ErrorHandler:
If Err.Number > 0 Then
MsgBox Err.Description, vbExclamation, "Error #: " & Err.Number
End If
Resume ExitProcedure
End Sub
Thanks for any help you can give.