Results 1 to 9 of 9
  1. #1
    HansBades is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    85

    Update VBA Query

    I can't get my update to work in my vba code. The relevant part is posted below. I am trying to change the category that a selected SKU falls into. The user chooses the SKU from a list box (Skuchosen variable). Choosing it indicates they want to update the category it belongs to. The update is supposed to change its category id to 10. But when I execute the code, I keep getting a message to enter a "parameter value". Any thoughts?


    strsql = "Update SKU " _
    & "Set SKUCategoryIDFK = 10 " _
    & "Where SKU = " & SKUCHOSEN _
    & ";"

    DoCmd.SetWarnings False
    DoCmd.RunSQL strsql

  2. #2
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    And that parameter prompt is ?? Maybe "Where SKU = " & SKUCHOSEN should be
    "Where SKU = '" & SKUCHOSEN & "'"
    assuming sku field is text data type.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  3. #3
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    does :
    SKUCHOSEN have a value?
    did you try running it as a query instead of code?

  4. #4
    HansBades is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    85
    Quote Originally Posted by ranman256 View Post
    does :
    SKUCHOSEN have a value?
    did you try running it as a query instead of code?

    Yes, SKUCHOSEN=Me.SKULISTBOX.Value
    One the form, I have a listbox with all the SKUS for a given category. The user chooses the applicable SKU in the listbox and then clicks a button to change its category. I am still getting a syntax error.

  5. #5
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,938
    Debug.print strSql and post back the output here.
    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

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    @HansBades

    To confirm, you have a form with a Listbox and you want to execute an Update query to change a record in your SKU table.

    What is the rowsource of your SKULISTBOX? (from where does it get its values)
    Are you using a specific form event to invoke the query? If so, which event?


    Using Debug.print strSQL will show you how Access has interpreted you sql. Great approach for debugging/confirming things before actually executing code.

    Please post all related code.

  7. #7
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,115
    Please try:
    Code:
    strsql = "Update SKU Set SKUCategoryIDFK = 10 Where SKU = " & Me.SKUCHOSEN 'assumes your listbox name is SHUCHOSEN and it is bound to a numeric column
    CurrentDb.Execute strsql,dbFailOnError
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  8. #8
    orange's Avatar
    orange is offline Moderator
    Windows 10 Office 365
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726

  9. #9
    HansBades is offline Advanced Beginner
    Windows 10 Office 365
    Join Date
    Dec 2021
    Posts
    85
    Everyone,
    Thank you. I think I got it working. I used Micron's suggestion. I didn't realize when I first tried it that I copied it incorrectly. Also, thank you everyone for the other tips. It will be very helpful to me going forward. Thanks again.

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: 6
    Last Post: 07-09-2021, 10:38 AM
  3. Replies: 1
    Last Post: 10-27-2016, 12:14 PM
  4. Replies: 7
    Last Post: 08-26-2013, 06:05 AM
  5. Replies: 2
    Last Post: 08-30-2012, 07:59 AM

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