Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / Database Access / April 2007



Tip: Looking for answers? Try searching our database.

How do I get the error messages from an insert statement with ADO?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bill - 13 Apr 2007 20:14 GMT
I have an insert statement in a function that I call repeatedly.

Let's say I call it 80 times and then there are 57 new records in my
table.

Presumably, the other 23 errored out for duplicate or other reasons.

How can I get the error message when an insert statement has errors?

Here is my code:

Public Function Run_Insert(sqlInsert As String) As ADODB.Recordset
On Error GoTo ExecuteError
Dim recSet As ADODB.Recordset
   
                               
   Get_Connection
   Set recSet = dbConn.Execute(sqlInsert)
   Set Run_Insert = recSet
   Exit Function
   
ExecuteError:

   strError = "Error in sub Utilities.Run_Insert" & vbCrLf &
Err.Number & _
               vbCrLf & Err.Description & vbCrLf & sqlInsert
                   
   Utilities.ErrorToFile (strError)
   
   Exit Function
End Function

Private Sub Get_Connection()
On Error GoTo ExecuteError
   
   'dbConn is a global variable.

   'Set the database
   db_file = "C:\Current Database\Test.mdb"
   
   'Open a connection to the database
   If dbConn Is Nothing Then
       Set dbConn = New ADODB.Connection
   
       dbConn.ConnectionString = _
           "Provider=Microsoft.Jet.OLEDB.4.0;" & _
           "Data Source=" & db_file & ";" & _
           "Persist Security Info=False"
       
       dbConn.Open (dbConn.ConnectionString)
       
   End If
   
   Exit Sub
   
ExecuteError:

   strError = "Error in Utilities.Get_Connection" & vbCrLf &
Err.Number &  vbCrLf & Err.Description
                   
   Utilities.ErrorToFile (strError)
   
   Exit Sub
   
End Sub

Thanks for your help.
Paul Clement - 16 Apr 2007 15:35 GMT
¤ I have an insert statement in a function that I call repeatedly.
¤
¤ Let's say I call it 80 times and then there are 57 new records in my
¤ table.
¤
¤ Presumably, the other 23 errored out for duplicate or other reasons.
¤
¤ How can I get the error message when an insert statement has errors?
¤

Check the Errors collection of the ADO Connection object.

Paul
~~~~
Microsoft MVP (Visual Basic)
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.