Append Query VB Code

K

Kjuib

How do I get an Append Query to run from VB?
My current code is:
Dim dbs As Database
Set dbs = OpenDatabase("J:\Backups\ClosingManager.mdb")
dbs.Execute " INSERT INTO UpdateLog([Date], Area,
Comment) VALUES(Now(), strArea, strComment);"
dbs.Close

strArea and strComment are Variables for Strings, but the
Query will not run, but If I put the strings in there It
will run... what can I do differently?
 
M

Marshall Barton

Kjuib said:
How do I get an Append Query to run from VB?
My current code is:
Dim dbs As Database
Set dbs = OpenDatabase("J:\Backups\ClosingManager.mdb")
dbs.Execute " INSERT INTO UpdateLog([Date], Area,
Comment) VALUES(Now(), strArea, strComment);"
dbs.Close

strArea and strComment are Variables for Strings, but the
Query will not run, but If I put the strings in there It
will run... what can I do differently?

You need to put the strings in the SQL statement, but you
can get an expression to do it for you:

strSQL = " INSERT INTO UpdateLog([Date], " _
& "Area, Comment) VALUES(" _
& Format(Now(), "\#m\/d\/yyyy h\:n\:s") & ", """ _
& strArea & """, """ & strComment & "");"
Debug.Print strSQL 'look at it in immediate/debug window
dbs.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

Similar Threads

Workspaces and BeginTrans 1
help with vb and access 1
Type Mismatch 2
VBA Code Help 3
Help running VB Code 1
Ken Snell's Multiple sheet export 3
Where is getstring? 6
Insert Table Row Loop 2

Top