PC Review


Reply
Thread Tools Rate Thread

Append Query VB Code

 
 
Kjuib
Guest
Posts: n/a
 
      30th Sep 2003
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?
 
Reply With Quote
 
 
 
 
Marshall Barton
Guest
Posts: n/a
 
      1st Oct 2003
Kjuib wrote:

>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

--
Marsh
MVP [MS Access]
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: VBA code to loop append query fails John Spencer Microsoft Access VBA Modules 1 16th Mar 2009 09:18 PM
Append Query code to VBA statement =?Utf-8?B?Q2xpbnQ=?= Microsoft Access Queries 2 8th Jun 2004 06:38 PM
Append parameter query via code Kurt Microsoft Access Form Coding 3 8th Jun 2004 05:56 PM
VBA code to run an append and a delete query SusanR Microsoft Access 1 5th May 2004 07:12 PM
Append query in code =?Utf-8?B?QmVja3k=?= Microsoft Access Queries 2 10th Mar 2004 04:06 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:57 PM.