know if query ran successfully

D

Daniel Pineault

Hello,

In my VBA code I created an SQL statement which I need to run. However, I
need a way of returning whether or not it ran successfully or not.

I tried the following
bSQl = db.Execute(sCSQL)

where sCSQL is my SQL string (obviously), but the compiler keeps spitting
out error (expecting function...).

the db.Execute sCSQL work fine on its own. I'm just messing things up when
I try and determine if it runs properly or not.

How can I return a value to a variable so I can determine if the query ran
properly or not?

Thank you,

Daniel P
 
D

Douglas J. Steele

Execute is a method, not a function.

You can use:

Dim dbCurr As DAO.Database

On Error Resume Next
Set dbCurr = CurrentDb()
dbCurr.Execute sCSQL, dbFailOnError
If Err.Number = 0 Then
MsgBox "The query ran successfully, and impacted " & _
dbCurr.RecordsAffected & " records."
Else
MsgBox "An error occured (Error Number " & Err.Number & _
": " & Err.Description & ")"
End If
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top