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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MS Example DAO Query not working??? 1

Status
Not open for further replies.

bjdobs

Programmer
Mar 11, 2002
261
CA
I have a stored query that references a Form variable:

select Count(*) as Foo
From sometable
where (((sometable.somefield) = [Forms]![SomeForm].[SomeObject]);

The MS Access knowledgebase is suggesting that I use this code to access a Query ... but I get an error saying there are too few parameters being passed ... Run-time Error 3061
Expecting 1

Dim dbo As DAO.Database
Dim rsc As DAO.Recordset

Set dbo = CurrentDb
Set rsc = dbo_OpenRecordset("SomeQuery")

I presume this has to do with the Forms!SomeForm.SomeObject?

the DAO.QueryDef has a parameters option but I can't seem to get the syntax right

Can someone please push me in the right direction.




 
You may try something like this:
Dim dbo As DAO.Database
Dim rsc As DAO.Recordset
Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter
Set dbo = CurrentDb
Set qdf = dbo.QueryDefs("SomeQuery")
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rsc = qdf.OpenRecordset(dbOpenDynaset)

Note: SomeForm must be an opened mainform

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top