Results 1 to 6 of 6
  1. #1
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94

    Too few parameters. 1 expected.

    I'm sure it's gonna end up being the silliest of things, but I'm out of ideas. I have this one form with three comboboxes with the same procedure. Basically, they all have a beforeupdate and an afterupdate event. When the combobox selection changes, the before update triggers and asks the user if they want to retire the previously selected entry (basically it just unchecks a checkbox and adds a retire date to that record).

    In two of the comboboxes the method works alright with the following code. Both of them locate the corresponding record through the autonumerated PK:
    Code:
    CurrentDb.Execute "Update tablename set ret_date = Now(), active=0 where id = " & Me.combobox.OldValue, dbFailOnError
    In the other combobox, that updates a table without an autonumerated PK, the "Too few parameters" error gets thrown. Since the where clause field is an string the code is the following, which is basically the same but with single quotes for the string
    Code:
    CurrentDb.Execute "Update tablename set ret_date=Now(), active=0 where serial_number = '" & Me.combobox.OldValue & "'", dbFailOnError
    The combobox.oldvalue gets displayed properly when printed to a confirmation msgbox before updating the table. Since its a variant, I tried converting it to string (with Cstr(combobox.OldValue) ) to no avail.

    How can I make it work for a String (short text) value? Where am I going wrong?

  2. #2
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Stick the whole statement into a variable and then try running that.

    Code:
    Dim strSQL as String
    
    strSQL = "Update tablename set ret_date=Now(), active=0 where serial_number = '" & Me.combobox.OldValue & "'"
    
    debug.print strSQL
    Currentdb.Execute strsql, dbfailonerror
    There might be some conflict trying to use refer to old value and updating the record at the same time?
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  3. #3
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    Ok, nevermind, I'm an idiot. I'd mispelled one of the fields (names are on spanish, but something like ret_data instead of ret_date) and for some reason, instead of telling me ret_data was not a field of the table it threw the error on the thread's title? I must have read the resulting query a hundred times and missed the little typo every single time, and I was starting to lose my mind. Access' misleading error didn't help.

    Anyway, thanks for your answer, Minty.

  4. #4
    Minty is offline VIP
    Windows 10 Office 365
    Join Date
    Sep 2017
    Location
    UK - Wiltshire
    Posts
    3,003
    Glad you got it spotted in the end.

    A debugging tip, if you use the technique of sticking the SQL in a string variable, you can paste the result from the immediate window into a blank new query design and try and run it, the error then generated is often much more specific/obvious in it's meaning.
    DLookup Syntax and others http://access.mvps.org/access/general/gen0018.htm
    Please use the star below the post to say thanks if we have helped !
    ↓↓ It's down here ↓↓

  5. #5
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    Access' misleading error
    Not misleading at all - you just didn't understand the message, so perhaps just not as clear as it could be. What you have is a query with parameters. If you point to a table that doesn't have the named field, misspell a field/object name, write sql in code in such a way that vba cannot resolve references, in short, do anything such that any parameter cannot be resolved, you get that message. It's on you to understand the messages presented and eventually you will get to understand most of them without having to research them.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  6. #6
    Lhoj is offline Advanced Beginner
    Windows 10 Access 2013 64bit
    Join Date
    Jun 2021
    Posts
    94
    Quote Originally Posted by Minty View Post
    Glad you got it spotted in the end.

    A debugging tip, if you use the technique of sticking the SQL in a string variable, you can paste the result from the immediate window into a blank new query design and try and run it, the error then generated is often much more specific/obvious in it's meaning.
    Nice tip, thanks Minty!

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

Similar Threads

  1. Too few parameters. Expected 1
    By carmenv323 in forum Access
    Replies: 17
    Last Post: 12-20-2021, 06:26 AM
  2. too few many parameters expected
    By DMT Dave in forum Access
    Replies: 3
    Last Post: 04-28-2020, 09:36 AM
  3. Too few parameters. Expected 1.
    By SierraJuliet in forum Programming
    Replies: 17
    Last Post: 02-01-2019, 02:28 PM
  4. Too few parameters expected 4
    By forestgump in forum Programming
    Replies: 1
    Last Post: 04-15-2011, 09:10 AM
  5. Too few parameters. Expected 2.
    By PPCMIS2009 in forum Access
    Replies: 0
    Last Post: 01-28-2009, 01:02 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