Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

OpenRecordset on a query question

Status
Not open for further replies.

daybase

Technical User
Dec 13, 2002
115
GB
I am moving away from macros etc into the exciting new world of VBA but being self taught I am struggling with some of the basics for now.

I have routines that open tables and move through the records which work perfectly well such as

Set db = CurrentDb
Set rst = db.OpenRecordset("tblproperties")
rst.MoveFirst
thisun = 0
thatun = 0
Do While rst.EOF = False
etc etc

I understand that it is possible to open a query as a recordset in the same way and use it in the same manner but I am having problems getting it to work

Set rst = db.OpenRecordset("QueryProperties")etc etc

Any assistance truly appreciated. Incidentally can anybody recommend a good reference book that aims at a reader somewhere between the levels of Computer Professor and a cabbage?

 
>I am having problems getting it to work

On which problem you need assistance?
 
Your can open a query as a recordset.

Try adding dbOpenDynaset

Code:
Set rst = dbs.OpenRecordset("qry", dbOpenDynaset)

This has worked for me.

 
I get an error message Runtime error 3061 Too few parameters.
 
So it is a parameter query?
Code:
Sub Lala()
   Dim qdfParameter As DAO.QueryDef
   Dim prmInputParameter As DAO.Parameter
   Dim myParameterValue As String
   Dim rst As DAO.Recordset

   myParameterValue='Trialarilalo'

   Set dbs=CurrentDB
   Set qdfParameter = dbs.QueryDefs("QueryProperties")
   Set prmInputParameter = qdfParameter.Parameters!TheParameterName
   prmInputParameter.Value=myParameterValue 

   Set rst = qdfParameter.OpenRecordset(dbOpenDynaset)
   Do While rst.EOF = False
...

   Loop
   rst.Close
   Set rst = Nothing
   Set prmInputParamter = Nothing
   Set qdfParameter = Nothing
   Set dbs = Nothing

End Sub
 
Too Few Parameters" is a common (frequently) error.

Mostly is means that by the lack of a parameters (or a parameter not found) that there is not a result for the query.

Test in your query if the parameter is working properly and if there is a query result.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top