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

Creating a RecordSet from a QueryDef Object.

Status
Not open for further replies.

databasis

Programmer
Feb 18, 2002
23
GB
Hello,

I create a New QueryDef and when the Query exists, I try to base a recordset on it with the usual code:

Set MyNewRecordset = MyJustCreatedQueryDef.OpenRecordset(type,options,etc)

But I keep getting the error that there are "too few parameters. Expected 11". Is it not an ordinary thing to do, to base a recordset on a QueryDef?

The way around it, I found was to make the QueryDef be a MAKE TABLE SQL and then the Recordset could be based always on the TABLE that the QueryDef created. This is using a lot of time as the table has to be deleted each time etc.

It'd be a whole lot easier if I could just base the recordset on the QueryDef. I wonder would some good soul be able to shed some light on this.

I'm using Access97, by the way. But in Access 2000 the error message is similar: "too few parameters, expected 1".

What am I doing wrong?

Maria
 
Maria,

Something is expecting a value to be passed to it. But when I have rec'd this error, I have found that I normally have mistyped the SQL. Can you post?

Craig
 
Maria,

Something is expecting a value to be passed to it. But when I have rec'd this error, I have found that I normally have mistyped the SQL. Can you post?

Craig
 
Hi Craig,

Thanks for replying. Here is a version of my code so you can see what I am trying to do....

Private Sub Test()
Dim MyDB As Database
Dim MyQdef As QueryDef
Dim MySQL As String
Dim MyRS As Recordset

MySQL = "SELECT *.Contacts FROM Contacts"
Set MyDB = CurrentDb()
Set MyQdef = MyDB.CreateQueryDef("EmailAddresses", MySQL)
Set MyRS = MyQdef.OpenRecordset(dbOpenDynaset)

etc.
etc.

End Sub


I entered 'dbOpenDynaset', but even when I enter all 3 parameters I keep getting the error. It's always fine up to that point. The query definition successfully makes the query. It's sitting there plain as day! Hope this sheds some light on my programming mistakes. I'll gladly accept criticism!

Maria
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top