Results 1 to 4 of 4
  1. #1
    T 5 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    3

    Update Query Syntax - RTE 424

    Hi,

    Could someone tell me where I am going wrong with the code below. Have tried numerous tweeks but nothing works.

    Dim varSql As String
    varSql = "UPDATE tblPriceList SET tblPriceList.SupplierID =" & Me.Combo45.Column(0) _
    & "WHERE tblPriceList.ProductID=" & Forms.frmProducts.cboFindProduct.Column(0) & "And" _


    & tblPriceList.SupplierID = " Forms.frmProducts.cboFindProduct.Column(4)"

    Thanks

  2. #2
    JoeM is offline VIP
    Windows XP Access 2007
    Join Date
    Jun 2012
    Posts
    3,904
    A few things:

    1. You need to leave space between your words so they don't run together.
    For example, replace "AND" with " AND ".

    2. Any Text criteria is going to need literal text qualifiers around them (double-quotes). These often get confused with the text qualifiers you are using to build your string in VBA. As such, I usually like to use Chr(34) to return a literal double-quote.
    So, are any of your fields (SupplierID or ProductID) text, or are they both numeric?

    There is an easy way of determining if you have written your SQL code correctly. Create a manual query in Query Builder that does EXACTLY what you want to do. Now switch to SQL code, and copy and paste the code out somewhere where you can reference it (NotePad, Word, etc). This is what the code you want to build in VBA should look like.

    Now, if your VBA code, after you have defined varSql, return it to a Message Box, i.e.
    Code:
    MsgBox varSql
    Compare that to the code you copied out. Does it match?

  3. #3
    T 5 is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2014
    Posts
    3
    Hmmm. I had no luck with this, so tried to create the query in the query builder, which would only go as far as the combo, not the combo column?
    In a little more researching, I have seen mention that the SQL query will only allow linking to one bound column, which would kind of suggest the reason why the builder doesn't do to the columns. There appears to be a work around of creating an invisible text box(s) which are linked to the combo column(s) value, which can then be referenced within the query!?

    Can anybody confirm if this actually true and if there is any better alternatives?

    Thanks and regards.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    If you are in SQL you only need one column from a ComboBox control. Use the Bound Column property of the combo to assign the Key value from the RowSource to the .Value property.

    Adding criteria to an SQL statement to include multiple columns of a combo is illogical.

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. Syntax Error 3144 in SQL Update Query.
    By Phred in forum Programming
    Replies: 4
    Last Post: 03-02-2012, 02:39 PM
  3. Replies: 7
    Last Post: 12-29-2011, 03:12 PM
  4. sql UPDATE syntax help
    By ducthang88 in forum Programming
    Replies: 1
    Last Post: 12-04-2010, 12:12 PM
  5. UPDATE query syntax
    By jgelpi16 in forum Programming
    Replies: 10
    Last Post: 08-21-2010, 07:40 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