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

Executing a parameter query in VBA

Status
Not open for further replies.

JulieS

MIS
Nov 23, 2000
48
CA
My combo box on my form is based off a parameter query.

In order to add a record to the form, I have to check if there are records or not (so I know if i should use the
DoCmd.GoToRecord , , acNewRec
command or not.

So, I'm trying to open this query (FunderCheck) with a recordset, but when i try to run this, my error is: "Too few
parameters. Expected 2". The form is open and the parameters are there, so i don't know quite what else to do. Here is the code (this is Access XP):

Dim rst as Recordset
Dim db As Database

Set db = CurrentDb

Set rst = db.OpenRecordset("FunderCheck",
dbOpenDynaset)

As an alternative, I'm thinking i may be able to have another query that counts how many (if any) records are counted in the FunderCheck query, i just don't know how to do it in VBA.

Thanks,
julie
 
Hi Julie

I am not an XP expert so treat this with caution. But I believe your code is DAO and by default XP uses ADO data objects. I think you have two choices:
1) Go to your reference library and make sure Microsoft DAO 3.6 object library is ticked, and move it as far up the list as possible
2)Be more specific with your code, eg
Dim rst As DAO.Recordset
Hope this helps
Nigel
Didn't someone say work is supposed to be fun? They didn't have computers then I guess....
 
I came across this when I was learning to use Access '97, it may still be valid. The query I was using was based on controls on the form the query was connected to. Whether the query is using the default pop-up parametric dialogs or based on controls on the form it is still a parametric query. To run the query from code it has to be actived using the QueryDef object and the parameters passed to it in code.

Dim dbs As Database
Dim qdef As QueryDef
Dim rst As Recordset
Dim frm As Form

Set qdef = dbs.QueryDefs("qryAATeamCount")
With qdef
.Parameters![Year] = frm!cboYear
.Parameters![Month] = frm!cboMonth
.Parameters![MRU:] = frm!cboMRUCode
Set rst = .OpenRecordset
With rst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top