Consulting

Results 1 to 2 of 2

Thread: DoCmd.RunSQL not working

  1. #1
    VBAX Newbie
    Joined
    May 2018
    Posts
    2
    Location

    DoCmd.RunSQL not working

    Can’t get this to work. AM I going about this the wrong way?
    I have spreadsheets sent daily, always with same headings
    Date Quantity SKU Number in numerical order Product Name Order Number Store Code Store Name

    I rename the spreadsheet adding my BAGcode.
    In MS Access I have a form which imports the spreadsheet into a table. This works well.
    My table has an additional column ‘BAGCode’ which I need to populate with the code I added when I renamed the spreadsheet.
    My code grabs the first 6 characters of the spreadsheet name into a variable. ‘bagCode’
    I then refresh the table.
    So I only update the records from the latest spreadsheet import, my code gets the ‘Order Number’ from the last record in the table to build a sql update statement.
    varsql = "UPDATE tblImportedOrderDetails SET tblImportedOrderDetails.BAGCode = " & bagCode & " WHERE [tblImportedOrderDetails.Order Number]= " & DLookup("[Order Number]", "tblImportedOrderDetails", "ID=" & DMax("ID", "tblImportedOrderDetails", "")) & ""
    I then run ‘DoCmd.RunSQL varsql’
    Because I can’t seem to get it to work I output via ‘MsgBox the varsql variable. Which look correct.
    msgbox.JPG
    When the last command is run ‘DoCmd.RunSQL varsql’ I get a popup box
    ask.JPG

    If I enter a value the correct records do get updated to what I just entered. Why does this popup box show?
    Would there be a better way to populate the additional column?

    First post so go easy

    Cheers

  2. #2
    VBAX Newbie
    Joined
    May 2018
    Posts
    2
    Location
    Well I don’t believeit , I have spent two dayson google trying to find the answer with no luck soposted to this forum.

    Went back togoogle for one last search and just found the answer .

    In my varsqlstatement I was missing the apostrophe (')

    tblImportedOrderDetails.BAGCode = "& bagCode & "

    should have been

    tblImportedOrderDetails.BAGCode =
    " & bagCode & "

    Thanks to those who may have read this post and mayhave been pondering this answer!!
    Cheers

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •