By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,510 Members | 1,437 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,510 IT Pros & Developers. It's quick & easy.

OpenRecordset Error!

P: 53
Hello
When i run this code,it give me a Runtime error(Too few parameters!).
Who knows what is the problem?
Query "FindMatchItemNo" works fine and has no problem.
Expand|Select|Wrap|Line Numbers
  1.  Set db = CurrentDb
  2.  Set rst = db.OpenRecordset("Select * from FindMatchItemNo")
  3.  
Best wishes for you
A.M
Apr 17 '10 #1

✓ answered by ADezii

@alinagoo
Your syntax is not correct, I've created a Code Template for you as a guideline:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim strQueryName As String
  4.  
  5. strQueryName = "FindMasterMatchItemNo"
  6.  
  7. Set MyDB = CurrentDb
  8.  
  9. 'Several Standard Options for Opening the Recordset
  10. 'Set rst = MyDB.OpenRecordset(strQueryName, dbOpenForwardOnly)
  11. '                          OR
  12. Set rst = MyDB.OpenRecordset(strQueryName, dbOpenDynaset)
  13. '                          OR
  14. 'Set rst = MyDB.OpenRecordset(strQueryName, dbOpenSnapshot)
  15.  
  16. With rst
  17.   Do While Not .EOF
  18.     'Let's Print the Values in the first 2 Fields
  19.     Debug.Print .Fields(0) & " " & .Fields(1)
  20.       .MoveNext
  21.   Loop
  22. End With
  23.  
  24. 'Clean Up chores
  25. rst.Close
  26. Set rst = Nothing

Share this Question
Share on Google+
3 Replies


TheSmileyCoder
Expert Mod 100+
P: 2,321
Have you tried looking at the help file for the OpenRecordset method?

It describes what parameters are needed and which are optional.
Apr 17 '10 #2

P: 53
@TheSmileyOne
Yes
It says: Openrecordset(queryname)
But it does not work too and return Too few parameters error!
Apr 17 '10 #3

ADezii
Expert 5K+
P: 8,601
@alinagoo
Your syntax is not correct, I've created a Code Template for you as a guideline:
Expand|Select|Wrap|Line Numbers
  1. Dim MyDB As DAO.Database
  2. Dim rst As DAO.Recordset
  3. Dim strQueryName As String
  4.  
  5. strQueryName = "FindMasterMatchItemNo"
  6.  
  7. Set MyDB = CurrentDb
  8.  
  9. 'Several Standard Options for Opening the Recordset
  10. 'Set rst = MyDB.OpenRecordset(strQueryName, dbOpenForwardOnly)
  11. '                          OR
  12. Set rst = MyDB.OpenRecordset(strQueryName, dbOpenDynaset)
  13. '                          OR
  14. 'Set rst = MyDB.OpenRecordset(strQueryName, dbOpenSnapshot)
  15.  
  16. With rst
  17.   Do While Not .EOF
  18.     'Let's Print the Values in the first 2 Fields
  19.     Debug.Print .Fields(0) & " " & .Fields(1)
  20.       .MoveNext
  21.   Loop
  22. End With
  23.  
  24. 'Clean Up chores
  25. rst.Close
  26. Set rst = Nothing
Apr 17 '10 #4

Post your reply

Sign in to post your reply or Sign up for a free account.