Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Docmd.quit error handling 1

Status
Not open for further replies.

benwah

Technical User
Jun 27, 2001
97
GB
Hi

I have a form with required fields. When the user quits the database and hasn't filled in all required fields an error is generated, but the option to quit is still there.

If the user ignores the warning and quits that record will be lost.

The warning that is given is to long-winded for the users so they dont bother reading it.

What i want is to replace this message with my own. Is that possible?

What i have been trying to do is capture the error. This will work with any command upon which an error occurs BUT not for the quit command. Here is what i have done as follows:


Private Sub cmdclose_Click()

On Error GoTo errortrap1

DoCmd.Quit 'acQuitSaveAll


errortrap1:
If MsgBox("Some or all required fields are incomplete. Quiting will result in deleting the current record. Do you wish to proceed?", vbYesNo, "Oh Dear!!") = 6 Then
Resume errorexit1
Else
Exit Sub
End If

errorexit1:
Application.Quit

End Sub


Any ideas anyone?

wah.
 
I would duplicate that error and determine what the error number is if it doesn't show(you indicate that its 6) by using:

msgbox "Err Number = " & err.number & " Err Description = " & err.description.

After determining the number then on your error handling routine you would use:

errortrap1:
dim response
if err.number = 6 'for example then
response = (msgbox "Some or all.. Quiting will result.. Do you wish to proceed?,vbYesNo,"Your header")
if response = vbyes then
Resume errorexit1
else
Exit Sub
end if
else
'you still want to trap other error messages

msgbox "Err Number = " & err.number & " has occured -> " & err.description.

end if

jlitondo@gatecitysteel.com
 
thanks for the response, i like your solution! One thing though, where in the code do i put the message function (ie MsgBox ("Err Number = " & Err.Number & " Err Description = " & Err.Description)) to determin the error number?

I have tried a number of positions but by that time the error has been and gone!

thanks again
wah
 
just use that msg for the very first time that you consciously duplicate that error message so that you can see what the error number is. Then delete it from your procedure.Good luck.
jlitondo@gatecitysteel.com
 
Thanks jlitondo that worked like a dream! Well almost anyway! Now when the message box is displayed it wipes all the data on the form. Any ideas? I have run out! ;)

thanks in advance
wah
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top