Suppress or alter error message

  • Thread starter Thread starter DWL
  • Start date Start date
D

DWL

I would like to supress the error message which comes as err.number 0.
"You can't save this record at this time. [MyApp] may have encountered
an error while tryign to save a record. If you close this object now,
the data changes you made will be lost. Doyou want to close the
database object anyway?

This occurs when the user uses the X in the upper right of the form to
close the application while it is in its validation routine. I want
the user to be able to exit the form (they don't know the answer)
without changing the current data - loosing the changes they made, BUT
I want the message to be more descriptionve AND have the option to
return to the form or close and loose the changes they made.

I added the error handling routine as in the code below which knows the
error is 0 and will display the message I have and I could add a
yes/no to do the return to the form BUT the message I listed above 0
message still displays. Any suggestions?


On Error GoTo HandleErrors
DoCmd.SetWarnings False
Dim blnContinue As Boolean
Dim ctl As Control
blnContinue = True

For Each ctl In Me.Controls

If ctl.Tag = "Required" Then
If IsNull(ctl) Then

MsgBox "You must fill in the " _
& ctl.ControlSource & " field."
Cancel = True
ctl.SetFocus
Exit For
End If
End If

Next ctl
Set ctl = Nothing
ExitHere:
DoCmd.SetWarnings True
Exit Sub

HandleErrors:
'MsgBox Err.Number
Select Case Err.Number
Case 0 ' You can't save this record at this time. Close
database object Yes/No
MsgBox "You did not complete a required field. Your data
changes will NOT BE SAVED."
Case Else
'Call a generic error handler
Call GenericHandler
End Select
Resume ExitHere
End Sub
 
You can put the code on the BeforeUpdate event so that the record can be
cancelled or undone

if validation does not pass...

'~~~~~~~~~~~~~~~~~~~~~~~~~~
Cancel = true

if MsgBox("Validation failed. YES to fill in rest of record, NO to
lose edits", vbYesNo,"Keep editing or Cancel") = vbNo then
me.undo
end if
'~~~~~~~~~~~~~~~~~~~~~~~~~~

"uses the X" -- this will trigger the form UnLoad event ...

Warm Regards,
Crystal
*
(: have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top