Quick VBA question

  • Thread starter rfuscjr via AccessMonster.com
  • Start date
R

rfuscjr via AccessMonster.com

I have a button on a form. It calls some queries then uses vba to loop. I
am stuck on syntax. Essentially I want to loop thru a table of ids one at a
time and do a few things along the way. I get stuck on my first task which
is to take the current id in the loop and write it into a table. I thought
the syntax would be something like this but it fails:

strSqlStmnt = "INSERT INTO tblReportProviderId ( SUI_Id )VALUES ('rstCCs!
SUI_Id')"
qdf.SQL = strSqlStmnt
qdf.ODBCTimeout = 0
qdf.Execute


Note that rstCCs!Id is the value of the current id in the table I am looping
thru. I tried with an without the single quotes and it fails.
 
R

rfuscjr via AccessMonster.com

well, I got some help...I never would have figured on this:

strSqlStmnt = "INSERT INTO tblReportProviderId ( SUI_Id )VALUES ('" & rstCCs!
SUI_Id & "')"
 
K

Klatuu

You are close, but the Excute statment is incorrect and the reference to the
recordset's field values has to be outside the quote marks when building the
string:

Dim strSQL As Strin

strSql = "INSERT INTO tblReportProviderId ( SUI_Id )VALUES (""" &
rstCCs!SUI_Id & """)"
Currentdb.Execute strSQL, dbFailOnError
 

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