Results 1 to 13 of 13
  1. #1
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672

    VBA Syntax For Append Query

    I am geting a syntax error with my syntax. I am sure it is something simple, but I have added double quotes and removed them but can't get the syntax perfect. How should this be changed so it is a valid VBA syntax?

    Code:
    appSQL = "INSERT INTO ProdData ( ICC, Description, SourceInfo, MinQTY, PriceBreal, salesRep ) " & _
                "SELECT [NIT].ICC, [ItemCode] & ' ' & [Description] AS FullDescription, "& SourceInfo & "," & MinQTY & "," & PriceBreal & "," & salesRep & " & _
                "FROM NIT;"


  2. #2
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    You need an AS fieldname for your second field. Add a line just after it Debug.Print appSQL and see what it produces.

  3. #3
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I am wanting to concatenate the 2nd & 3rd together.
    [ItemCode] & ' ' & [Description] AS FullDescription

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    That's field 1. The second field is also a concatenation but there is no field name.

  5. #5
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Unless I am mising the obvious here, wouldn't field one be [NIT].ICC and field 2 would be [ItemCode] & ' ' & [Description] AS FullDescription

  6. #6
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Query field name, not table field name.

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    Sorry, field 3.

  8. #8
    jwhite is offline Competent Performer
    Windows 10 Access 2013 32bit
    Join Date
    Dec 2012
    Location
    North Carolina
    Posts
    349
    PMFJI... You have extraneous characters at the end of the second line: salesRep & " & _

    Try removing & " directly after salesRep

  9. #9
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by jwhite View Post
    PMFJI... You have extraneous characters at the end of the second line: salesRep & " & _

    Try removing & " directly after salesRep
    That gives an error of Compile error syntax error on the after the field I removed. " &

  10. #10
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    Quote Originally Posted by aytee111 View Post
    Query field name, not table field name.
    Addingin an "As" and aliasing my variables for names now removes the error

  11. #11
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    You need the & _ at the end to get the From clause on the next line.

    Try copying that code into a new query in the SQL designer, then select the Design look and see where it is placing the fields and criteria. Try running it from that query designer and if works, can view the SQL code and use that in VBA if you want. You can also leave it as a Query and do Docmd.RunQuery "YourAppendQuery"

  12. #12
    Bulzie is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    Nov 2015
    Posts
    1,471
    Also on the Select maybe:
    "SELECT [NIT].ICC, [ItemCode] & ' ' & [Description] AS FullDescription, [SourceInfo], [MinQTY], [PriceBreal], [salesRep] From NIT;"

  13. #13
    Micron is online now Virtually Inert Person
    Windows 7 32bit Access 2007
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,793
    I don't understand all the concatenation after the desired concatenation of the 2nd and 3rd field. If you string the rest together, the number of selected fields doesn't match the number of fields listed in the insert portion. Maybe I'm interpreting it wrong, but isn't it more like

    Code:
    appSQL = "INSERT INTO ProdData (ICC, Description, SourceInfo, MinQTY, PriceBreal, salesRep) " & _
            "SELECT [NIT].ICC, ([ItemCode] & ' ' & [Description] AS FullDescription), SourceInfo, MinQTY, PriceBreal, salesRep FROM NIT;"
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

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

Similar Threads

  1. Replies: 10
    Last Post: 10-30-2013, 02:06 PM
  2. Append Query From Form Syntax Error
    By burrina in forum Forms
    Replies: 8
    Last Post: 01-02-2013, 10:37 AM
  3. Replies: 1
    Last Post: 10-06-2011, 08:37 AM
  4. Replies: 7
    Last Post: 07-21-2011, 01:01 PM
  5. Urgent: SQL Append Query Syntax
    By rushforth in forum Import/Export Data
    Replies: 14
    Last Post: 02-23-2011, 02:44 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