Results 1 to 7 of 7
  1. #1
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253

    Help with error 3061 too few parameters. Expected 1



    Code:
    Set rst = cDB.OpenRecordset("qryGetPartName")
    This line of code is giving me the error. When i run the query in the query builder it works like it is supposed to. An input box opens i put in the number i want and the results are correct. I am not understanding why i am getting this error. Here is the SQL from the query builder. I even relinked all the tables. Thank you for any help.

    Code:
    SELECT qryVendorToPart.PartID, qryVendorToPart.PartNumber, qryVendorToPart.PartName, qryVendorToPart.VendorID
    FROM qryVendorToPart
    WHERE (((qryVendorToPart.VendorID)=[varVendor]));

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,524
    do you need the recordset in code?
    normally you just run: docmd.openquery "qryGetPartName"
    the see the records.

    if you DO need the rst in code, then [varVendor] has no meaning here.
    Is it a field on a form, then you must use the FULL path: forms!fMyform!varVendor

    if varVendor is a vb variable , you cannot put it in brackets:
    ...WHERE (((qryVendorToPart.VendorID)=" & varVendor & "));"

    if the query doesn't understand the criteria, it will think its a parameter.

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    Query object with popup input parameter will not work when that query object is called in VBA.

    As Ranman suggests, either:

    1. query object references a control on form

    or

    2. use complete SQL string in VBA and concatenate variable - variable can be reference to control or an InputBox() function (I recommend a control)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I am trying to make the query a rowsource for a combobox depending on what is in the first combobox (cboVendor). in the code just above the set rst statement I have
    Code:
    If Not IsNull(cboVendor.Value) Then
            varVendor = cboVendor
    . I use this on many forms but i had it all in a sql = SELECT statement. I ran into problems when the Select statement needed to be changed and only one location got changed. I am trying to fix that by using an actual query.

    I tried taking out the brackets but the query builder keeps putting them back.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    You don't need a recordset just to set RowSource of a combobox.

    Brackets are not a problem. Use of varVendor is, as already explained.

    Query object cannot reference VBA variable. Query object can reference TempVars. I have never used TempVars. Query object can also reference a VBA Function procedure (not a Sub).
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    NightWalker's Avatar
    NightWalker is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Apr 2016
    Location
    Midwest USA
    Posts
    253
    I have been googling cascading comboboxes and have not found a way to do it without a SQL = SELECT statement in the VBA. If you could point me in the right direction I would be more than happy to give it a go. Thank you for your help.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,913
    How will this query object fix locations that used an SQL statement in RowSource? Or did they all reference a query object? If you want to use query object then must use full form/control path per Ranman example. If you are trying to fix multiple comboboxes on multiple forms, this referencing will not work unless they are all dependent on the same Forms!formname!cboVendor.

    Assuming comboboxes are on same form, dependent combobox can have RowSource as SQL statement like:

    SELECT qryVendorToPart.PartID, qryVendorToPart.PartNumber, qryVendorToPart.PartName, qryVendorToPart.VendorID
    FROM qryVendorToPart
    WHERE (((qryVendorToPart.VendorID)=[cboVendor]));

    Then VBA just needs to Requery combobox:

    Me.cboParts.Requery

    Otherwise, yes, VBA will set RowSource = "Some SQL statement"

    Still, there is no need for recordset object.

    Be aware that dependent combobox using alias will not work nicely with form in Datasheet or Continuous view.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Replies: 4
    Last Post: 09-28-2016, 07:13 AM
  2. Error 3061. Too few parameters. Expected 1.
    By Glenn_Suggs in forum Programming
    Replies: 5
    Last Post: 02-03-2015, 12:03 PM
  3. Runtime Error 3061. Too few parameters, expected 2
    By Gina Maylone in forum Programming
    Replies: 35
    Last Post: 01-13-2014, 02:37 PM
  4. Replies: 3
    Last Post: 04-26-2013, 01:37 PM
  5. 3061 Error. Too few parameters. Expected 1.
    By rghollenbeck in forum Queries
    Replies: 5
    Last Post: 09-28-2011, 12:12 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