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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how can I compose my own error messages? 2

Status
Not open for further replies.

james33

Technical User
Dec 23, 2000
1,345
IE
You may all know this one, but I would really appreciate a hand please.

In a form when the Command Button 'Undo Edit' is pressed a VB procedure returns an error message, as follows:

The command or Action Undo isn't available now. and
*You may be in a read only database...etc
*The type of Object the action applies to...etc
followed by:
Use only those commands and Macro actions that are currently available for this database

This appears to be associated with the following Code

MsgBox Err.Description

The full procedure is as follows:

Code:
Private Sub CmdUndoAll_Click()
On Error GoTo Err_CmdUndoAll_Click


    DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, , acMenuVer70

Exit_CmdUndoAll_Click:
    Exit Sub

Err_CmdUndoAll_Click:
    MsgBox Err.Description
    Resume Exit_CmdUndoAll_Click
    
End Sub


My question is: How can I get into the 'Description' and compose my own error messages and have them shown at this point?
regards
Jim
 
What you want to do is to trap the error number and don't display err.description at all. Something like this:

Err_CmdUndoAll_Click:
If Err.Number = "3349" Then
Message = "Custom err message"
MsgBox Message, vbCritical
Else
MsgBox Err.Number & " " & Err.Description
End If

Just substitute your error number for 3349. B-)
 
James:

I'm not sure but I think the error is occuring because you are trying to undo a record that has not been changed (?).

If so, use this:

If Dirty Then
DoCmd.DoMenuItem acFormBar, acEditMenu, acUndo, ,
acMenuVer70
End If

This will test teh Dirty property of the record and only execute the undo if the record has been modified.

Hope this helps.
Larry De Laruelle
larry1de@yahoo.com

 
Thank you both for your speedy answers this is the best place..... anywhere!
Regards
Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top