Article ID: 129165
Article Last Modified on 11/6/2000
Function TrapODBCError ()
On Error GoTo ErrorHandler
Dim mydb As Database
Dim myrs As Recordset
Dim ErrorString As String, ErrorNum As Double
Dim ErrorStart As Integer, ErrorLength As Integer
Set mydb = CurrentDB()
Set myrs = mydb.OpenRecordset("dbo_authors", db_open_dynaset,_
db_appendonly)
myrs.AddNew
myrs.au_id = "xxx"
myrs.au_lname = "Smith"
myrs.contract = 0
myrs.Update
Exit Function
ErrorHandler:
ErrorString = Error$
'Find the beginning of the error string. It begins with "#."
ErrorStart = InStr(1, ErrorString, "#") + 1
'Find the length of the error value.
ErrorLength = InStr(ErrorStart, ErrorString, ")") - ErrorStart
'Get the error number.
ErrorNum = Mid(ErrorString, ErrorStart, ErrorLength)
MsgBox "Error number " & CStr(ErrorNum) & " has occurred."
Exit Function
End Function
Keywords: kbinfo kbusage KB129165