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

VB and Access

Status
Not open for further replies.

BTawil

Programmer
Mar 6, 2001
4
0
0
IT
Hia,
I am developping a small program with VB 6.0 connected to an Access Database.
Sometimes when i insert a record into a table of the database, i get no error messages, but the record is not inserted ... I try to run the query again from access and i get an error message (Ex: when i try to insert a text fiels that contains an appostrophy)
How can i make sure that i get all the errors that occur with access into my VB programme so i can handle them.
thanks in advance
Bassam
 
The MSDN Library Visual Studio 6.0 provides a useful description and example of the Errors Collection.

Note that this assumes that you are using ADO.

See below.

Any operation involving ADO objects can generate one or more provider errors. As each error occurs, one or more Error objects can be placed in the Errors collection of the Connection object. When another ADO operation generates an error, the Errors collection is cleared, and the new set of Error objects can be placed in the Errors collection.

Each Error object represents a specific provider error, not an ADO error. ADO errors are exposed to the run-time exception-handling mechanism. For example, in Microsoft Visual Basic, the occurrence of an ADO-specific error will trigger an On Error event and appear in the Err object.

This example forces an error, traps it, and displays the Description, Number, Source, HelpContext, and HelpFile properties of the resulting Error object.

Sub DescriptionX()

Dim dbsTest As Database

On Error GoTo ErrorHandler

' Intentionally trigger an error.
Set dbsTest = OpenDatabase("NoDatabase")

Exit Sub

ErrorHandler:
Dim strError As String
Dim errLoop As Error

' Enumerate Errors collection and display properties of
' each Error object.
For Each errLoop In Errors
With errLoop
strError = _
"Error #" & .Number & vbCr
strError = strError & _
" " & .Description & vbCr
strError = strError & _
" (Source: " & .Source & ")" & vbCr
strError = strError & _
"Press F1 to see topic " & .HelpContext & vbCr
strError = strError & _
" in the file " & .HelpFile & "."
End With
MsgBox strError
Next

Resume Next

End Sub

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top