append query vs SQL INSERT

G

Gregg

I want to insert records into an Access 2003 .mdb table.
Append queries don't seem to fit since I will be
inserting different numbers of records depending on user
input in a form. Creating a module using INSERT from SQL
in a loop seems perfect, but I can't find how to execute
the SQL statement that I would assemble in that loop. Is
there a RunSql command or something similar? Thanks!
 
A

Allen Browne

Try:
dbEngine(0)(0).Execute "INSERT ...", dbFailOnError

You can use DoCmd.RunSql, but you don't know if it succeeded.

With the Execute method, you can also examine RecordsAffected (the number of
inserts), and even use a transaction for an all-or-nothing result.
Transaction details and example:
http://allenbrowne.com/ser-37.html
 

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