Results 1 to 4 of 4
  1. #1
    MatthewGrace is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2013
    Posts
    159

    Access falsely believes I'm my recordset requires a parameter

    Thank you for taking the time to consider my question.

    I have some code that looks like this:
    Code:
    Dim rs As Recordset
    Set rs = CurrentDb.OpenRecordset("qryOrphan", dbOpenSnapshot) 'This line errors.
    It says:
    Run-time error 3061. Too few parameters. Expected 1.

    I was confused. "qryOrphan doesn't take any parameters. What in blazes is going on here?"
    Then I saw it: the Criteria for one of the fields reads:



    >=DateAdd("d",[Forms]![frmReports]![cboHistory],Now())

    The aforementioned cboHistory combobox contains a number of days like -90. Anyhow the query works fine when I double click on it in the Navigation Pane. It doesn't ask for a parameter.

    My guess is that for some reason, VBA code seems to falsely interpret the [ ] in my Forms collection as being a parameter.

    Do I understand this correctly? Is there a way around this?

    Thanks for any help.
    Matt

  2. #2
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,121
    This is to be expected when you use it like that. You need to force the evaluation of the parameters before you attempt to create the recordset:
    Code:
    Dim rs As DAO.Recordset,qdf as DAO.Recordset,prm as Parameter
    
    
    Set qdf=CurrentDb.QueryDefs("qryOrphan")
    
    
    For Each prm in qdf.Parameters
      prm.Value=Eval(prm.Name)
    Next prm
    
    
    Set rs =qdf.OpenRecordset(dbOpenSnapshot)
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

  3. #3
    MatthewGrace is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Jan 2013
    Posts
    159
    Thanks Vlad. I had a feeling it was something like this.

    Hey I noticed 2 things:

    Firstly you said DAO.Recordset. Not really sure about the DAO part. Isn't that automatic? I've never used it before. I just say Dim rs as Recordset.
    Second, I noticed you Dim'd "qdf as DAO.Recordset". Did you mean DAO.Querysomething? QueryDef?

    Thanks,
    Matt

  4. #4
    Gicu's Avatar
    Gicu is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Jul 2015
    Location
    Kelowna, BC, Canada
    Posts
    4,121
    Sorry Matt, yes, it should be "qdf as DAO.QueryDef", just writing it in Notepad with no help from IntelliSense . I always like to fully qualify the declarations to avoid problems as "Dim rs as Recordset" could be interpreted as an ADO recordset depending on how the references are set up (the order in which they appear).
    Cheers,
    Vlad Cucinschi
    MS Access Developer
    http://forestbyte.com/

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

Similar Threads

  1. Replies: 3
    Last Post: 11-30-2018, 05:03 PM
  2. Last combo box requires to enter Parameter
    By Tompham89 in forum Database Design
    Replies: 10
    Last Post: 05-19-2015, 08:13 AM
  3. Recordset Given too few parameter error
    By boywonder381 in forum Programming
    Replies: 1
    Last Post: 11-11-2014, 12:07 AM
  4. Running Parameter Requires Table ID# Not Field Name
    By gabrielnerf in forum Queries
    Replies: 3
    Last Post: 02-05-2012, 12:34 AM
  5. Display Query Value That Requires Input Parameter
    By Access::Student in forum Access
    Replies: 1
    Last Post: 05-29-2009, 08:43 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