DAO.OpenRecordset throws an error but SQL is good

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • modmans2ndcoming
    New Member
    • Sep 2008
    • 11

    DAO.OpenRecordset throws an error but SQL is good

    According to Access 2007, when I use the query builder, this sql code returns exactly what I want from my table

    Code:
    Select reports.[rptName] FROM reports WHERE (((reports.rptLable)=[Forms]![startup]![rptPicker]));
    but when I am using the DAO.OpenRecords et method to run the sql statement I get an error saying "to few parameters. Expected 1"

    Any help resolving this will be greatly appreciated.

    Thanks
  • modmans2ndcoming
    New Member
    • Sep 2008
    • 11

    #2
    I solved my problem.

    It appears DAO.OpenRecords et does not like all the stuff that Access throws around like the form hierarchy and stuff. so I replaced the [forms]!... with a variable name and concantinated it in and it worked.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32656

      #3
      That's about it. And thanks for letting us know it's resolved.

      Object references like that are valid within VBA but not from all areas (Like the DAO Jet SQL engine). I can't fully explain why it runs ok when dropped into the SQL page of a QueryDef.

      Comment

      Working...