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

Error message trapping 1

Status
Not open for further replies.

teknogeek9

Programmer
Jan 6, 2001
47
US
I have been looking throughout the Access forums for a list of error message numbers. I have not been able to find any. Essentially, I want to replace the "user-unfriendly" MS Access messages with my own.

For example, I would like to trap the message "The record cannot be deleted or changed because table 'tblCustPref' includes related records." and replace it with my own No message number is given.

Any assistance would be appreciated. Thanks!
 
I can't seem to locate a routine that traps the error. However, there is an error code assigned to it. You need to check for it in the forms OnError event.
 
see also

thread702-523334

Judge Hopkins

"...like hunting skunks underwater...."
John Steinbeck, The Grapes of Wrath
 
Oops, that's really old code I linked to above.
You can use the following for Access 97.

'You can run this function to create Error Code Table.

Function AccessAndJetErrorsTable() As Boolean
Dim dbs As Database, tdf As TableDef, fld As Field
Dim rst As Recordset, lngCode As Long
Dim strAccessErr As String
Const conAppObjectError = "Application-defined or object-defined error"

On Error GoTo Error_AccessAndJetErrorsTable
' Create Errors table with ErrorNumber and ErrorDescription fields.
Set dbs = CurrentDb
Set tdf = dbs.CreateTableDef("AccessAndJetErrors")
Set fld = tdf.CreateField("ErrorCode", dbLong)

tdf.Fields.Append fld
Set fld = tdf.CreateField("ErrorString", dbMemo)
tdf.Fields.Append fld

dbs.TableDefs.Append tdf
' Open recordset on Errors table.
Set rst = dbs.OpenRecordset("AccessAndJetErrors")
' Loop through error codes.
For lngCode = 0 To 3500
On Error Resume Next
' Raise each error.
strAccessErr = AccessError(lngCode)
DoCmd.Hourglass True
' Skip error numbers without associated strings.
If strAccessErr <> &quot;&quot; Then

' Skip codes that generate application or object-defined errors.
If strAccessErr <> conAppObjectError Then
' Add each error code and string to Errors table.
rst.AddNew
rst!ErrorCode = lngCode
' Append string to memo field.
rst!ErrorString.AppendChunk strAccessErr
rst.Update
End If
End If
Next lngCode
' Close recordset.
rst.Close
DoCmd.Hourglass False
RefreshDatabaseWindow
MsgBox &quot;Access and Jet errors table created.&quot;

AccessAndJetErrorsTable = True

Exit_AccessAndJetErrorsTable:
Exit Function

Error_AccessAndJetErrorsTable:
MsgBox Err & &quot;: &quot; & Err.Description
AccessAndJetErrorsTable = False
Resume Exit_AccessAndJetErrorsTable
End Function

paste the code into a module, save it and then type '?AccessAndJetErrorsTable()' into the debug window and you will get a table listing all Acc97 error codes and descriptions. I do not know where I first got this code so I cannot give credit unfortunately.

If anyone has similar code or wants to modify this code for Acc2000 or 2002 it would be worth posting here.
 
Thanks to all those who have helped. I guess Bill Gates doesn't want to make our lives any more easier!
:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top