Results 1 to 10 of 10
  1. #1
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566

    Update

    Hi

    Can someone tell me where the syntax is wrong in the following:-

    20 strSQL = "UPDATE Part_Number SET Part_Price_Spare2_Notes = "Open" WHERE Job_PartNumber = '" & Me.PartNoID & ";"

    The line of Code is highlighted in Red

    Any help appreciated
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,957
    No red.
    Debug.print the sql string and post that.
    Most likely your double quotes within double quotes?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi Welshgasman

    I should have said that both Job_PartNumber and PartNoID are Strings and I cannot change this.


    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  4. #4
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    I cannot understand why it is highlighting "open"
    Attached Thumbnails Attached Thumbnails error.JPG  
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  5. #5
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Try

    Code:
    strSQL = "UPDATE Part_Number SET Part_Price_Spare2_Notes = 'Open' WHERE Job_PartNumber = '" & Me.PartNoID & "';"
    It's highlighting open because you used double quotes there without escaping. You can use either double " or single ' quotes to open and close a string. If you use double quotes to open and close the string then use single quotation marks to enclose strings within the string, or vise versa. Or you can escape the string characters within the string.
    https://software-solutions-online.co...pe-characters/

  6. #6
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,957
    Quote Originally Posted by mike60smart View Post
    Hi Welshgasman

    I should have said that both Job_PartNumber and PartNoID are Strings and I cannot change this.
    Yet you use single quotes for those and double quotes for Open?

    You are not even using PartNumber except as a literal.?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  7. #7
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    I was always under the impression if I was using text then they should always be enclosed in Double Quotes.

    If I was making a reference to a Control whose data type was Text then use a Single & Double to enclose.
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  8. #8
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,957
    Quote Originally Posted by mike60smart View Post
    I was always under the impression if I was using text then they should always be enclosed in Double Quotes.

    If I was making a reference to a Control whose data type was Text then use a Single & Double to enclose.
    Text is text?
    So how is Access meant to know when the string ends as opposed to a value being added?

    @kd2017 has posted some code, which I would have thought was the solution?, just that I wanted you to think for it by yourself. Have you tried that?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  9. #9
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    Hi KD

    That didn't work either - gives the error Too Few Parameters. Expected 1

    I have gone with an Update query and it works just fine

    Many thanks for looking
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  10. #10
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Quote Originally Posted by mike60smart View Post
    Too Few Parameters. Expected 1
    First thing I do when I see that error is double check that table name, field name, and form object names don't have typos.

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

Similar Threads

  1. Replies: 4
    Last Post: 03-09-2022, 11:28 AM
  2. Replies: 2
    Last Post: 06-21-2018, 03:16 AM
  3. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  4. Replies: 2
    Last Post: 08-30-2012, 07:59 AM
  5. Replies: 1
    Last Post: 01-22-2011, 12:23 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