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

Access, Jet, and/or VB Error Messages 1

Status
Not open for further replies.
Oct 24, 2002
512
US
Does anybody know where I can find a list (preferably one that I can import into a table for sorting, searching, etc.) of error codes?

For example, I'm getting a message "primary or key field cannot contain a null value". I expect (and want) this to occur but I want to trap the error and display a more meaningful message. Problem is, I don't know how to find the error number for that error description.

Is there a way to ask for the number by entering a statement in the Immediate window?

Thanks for any help.
Ann
 
Take a look at the ErrorHandler code. You could use it to get the error# then edit the If statement to whatever you want


Private Sub cmdSave_Click()
On Error GoTo ErrorHandler

Dim db As Database
Dim rs As DAO.Recordset
Dim errE As Error

If IsNull(Forms![Add Brand2].[txtBrandName]) Then
MsgBox "There are no entries to Save"
Else
Set db = CurrentDb
Set rs = db.OpenRecordset("Brand", dbOpenDynaset)

With rs
.AddNew
.Fields("BrandName") = Forms![Add Brand2].[txtBrandName]
.Update
End With

MsgBox "Your entry has been added successfully"

End If

ErrorHandler:

If Err.Number = 0 Or Err.Number = 20 Then
'Do nothing
Else
MsgBox "Err = " & Err.Number & ": " & Err.Description

For Each errE In DBEngine.Errors
MsgBox "err = " & Err.Number & ": " & Err.Description
Next
End If
Resume ExitHere

ExitHere:
Set rs = Nothing
Set db = Nothing

Me!cboSeeBrand = Null
Me!cboSeeBrand.Requery

Exit Sub

End Sub


Remember amateurs built the ark - professionals built the Titanic

[yoda]
 
MazeWorX, thanks a bunch. I applied your code and found my error (#3058). I'm new to this error handling stuff but I can see I'm gonna love it once I get the hang of it.

Thanks again!
Ann
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top