Results 1 to 3 of 3
  1. #1
    hawg1 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2010
    Posts
    9

    Append Query using variables

    Hi,

    I have written an append query using the query wizrd for a specific table, then convertedit into Vb.
    Code:
    DoCmd.RunSQL "INSERT INTO WUC ( WUC, DESCRIPTION ) SELECT NEWWUC.WUC AS Expr1, NEWWUC.DESCRIPTION AS Expr2 FROM NEWWUC"
    I would now like to use that same append query but use variables for the table names, etc. Can anyone provide assistance in this matter?

    Thanks
    Hawg1

  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Read up on concatenation in VBA. You will create a variable string that holds the query you want run then run the string variable in your RunSQL

    dim strSQL as String

    strSQL = "INSERT INTO " & tableName & "..."

    DoCmd.RunSQL (strSQL)

    replace the ... with the rest of your SQL using the same string construction pattern of " & var & " to insert variables wherever they need to be.

  3. #3
    hawg1 is offline Novice
    Windows Vista Access 2007
    Join Date
    May 2010
    Posts
    9
    Quote Originally Posted by TheShabz View Post
    Read up on concatenation in VBA. You will create a variable string that holds the query you want run then run the string variable in your RunSQL

    dim strSQL as String

    strSQL = "INSERT INTO " & tableName & "..."

    DoCmd.RunSQL (strSQL)

    replace the ... with the rest of your SQL using the same string construction pattern of " & var & " to insert variables wherever they need to be.
    TheShabz,

    Sorry for the delay, tied up at work. Thanks for the info, it is a great help. I'll also read up on concatenation.

    Thanks

    Hawg1

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Append query won't append
    By yelkenli in forum Queries
    Replies: 5
    Last Post: 02-12-2010, 11:19 AM
  2. Append Query
    By aabh in forum Queries
    Replies: 6
    Last Post: 02-02-2010, 04:26 PM
  3. Append Query
    By cotri in forum Queries
    Replies: 1
    Last Post: 01-28-2010, 08:52 PM
  4. append query error
    By shashigk in forum Queries
    Replies: 2
    Last Post: 09-22-2009, 07:17 AM
  5. Access append query
    By antoniorossano in forum Queries
    Replies: 1
    Last Post: 08-26-2009, 01:17 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums