multiple "INSERT INTO" queries

S

setterst

Hopefully all of you can once again help me with a problem I am having
running multiple INSERT queries in my VBA code. My code looks
something like this:

' Form condition 1
If condition1 = True Then
CurrentDb.Execute "INSERT INTO tblTable " & _
"(Field_1, Field_2, Field_3)" & _
"VALUES (Val_1, Val_2, Val_3)"
End If

' Form condition 2
If condition2 = True Then
CurrentDb.Execute "INSERT INTO tblTable " & _
"(Field_1, Field_2, Field_3)" & _
"VALUES (Val_1, Val_2, Val_3)"
End If

And the code continues like this for multiple form conditions.

So here is the problem. All of my queries will function properly when
they are executed individually, but when multiple form conditions are
true, only the first query will append its values to the destination
table. I verified with the debugger that I have my conditions
correctly configured and it is executing the commands. Am I missing
something here?

Your help is always appreciated.

-Sean
 
G

Guest

You can't really see what is happening. Try:

CurrentDB.Execute "...", DAO.dbFailOnError

(david)
 
P

Pat Hartman\(MVP\)

Are you saying that you want to be able to insert multiple rows with this
code? As it is presented here, all the SQL strings are identical so
assuming you have a pk or unique index defined, the second and subsequent
inserts would fail because they insert duplicate records.
 

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

Top