A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Suppress or alter error message



 
 
Thread Tools Display Modes
  #1  
Old December 28th, 2006, 07:24 PM posted to microsoft.public.access.forms
DWL
external usenet poster
 
Posts: 3
Default Suppress or alter error message

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
ExitHe
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

  #2  
Old December 29th, 2006, 01:53 AM posted to microsoft.public.access.forms
strive4peace
external usenet poster
 
Posts: 1,670
Default Suppress or alter error message

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
*



DWL wrote:
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
ExitHe
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

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 09:01 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.