OpenRecordset problem (1 Viewer)

fmm

Registered User.
Local time
Today, 01:45
Joined
Mar 15, 2001
Messages
76
Here's my code:

Private Sub test_Click()
On Error GoTo Err_test_Click

Dim dbs As Database, rst As Recordset, intRecordCount As Integer

Set dbs = CurrentDb

Set rst = dbs.OpenRecordset("qryQCMainSizeCheck", dbOpenDynaset)


I get the following error message:
"Too few parameters. Expected 1."

This is error #3061.

Any ideas?

Thanks!
 
Last edited:

Howlsta

Vampire Slayer
Local time
Today, 07:45
Joined
Jul 18, 2001
Messages
180
I had this problem about 1-2 weeks ago and didn't know what it was all about. I got help from Pat which was the following:

When parameter queries are run from VBA, you need to supply the parameters. I would change the parameter names in the query so that instead of being [Forms!YourForm!YourControl], they are [SomeMeaningfulName].
Set rst = db.QueryDefs!qryQCMainSizeCheck
rst.Parameters![SomeMeaningfulName] = Me.YourControl
rst.OpenRecordset

If you are using controls to hold the parameters like I was otherwise ignore Me.YourControl

Maybe Pat can help you more.

Rich
 

Howlsta

Vampire Slayer
Local time
Today, 07:45
Joined
Jul 18, 2001
Messages
180
Also check the threads i started called

Invalid use of Property and also 2 few parameters. One is in the Module and one in the general forum within the last 20 days.

HTH

Rich
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:45
Joined
Feb 19, 2002
Messages
43,565
If your query takes parameters, you need to supply them before opening the recordset.

Dim dbs As Database
Dim rst As Recordset
Dim intRecordCount As Integer
Dim qd As QueryDef
Set dbs = CurrentDb
Set qd = dbs.QueryDefs!qryQCMainSizeCheck
qd.Parameters![YourParm] = SomeValue
Set rst = dbs.OpenRecordset
 

DocNice

Registered User.
Local time
Yesterday, 23:45
Joined
Oct 6, 2004
Messages
76
Pat Hartman said:
If your query takes parameters, you need to supply them before opening the recordset.

Dim dbs As Database
Dim rst As Recordset
Dim intRecordCount As Integer
Dim qd As QueryDef
Set dbs = CurrentDb
Set qd = dbs.QueryDefs!qryQCMainSizeCheck
qd.Parameters![YourParm] = SomeValue
Set rst = qd.OpenRecordset
I fixed this, Pat

I don't understand what [YourParm] and SomeValue represent. What should I be placing in these areas?

Also, I want this code to open a recordset based on a query.

Should I put in:
Set qd = dbs.QueryDefs!myqueryname
Does this replace the code I would place under the parenthesis after OpenRecordSet(type, source, etc)

Thanks in advance!
 
Last edited by a moderator:

KenHigg

Registered User
Local time
Today, 02:45
Joined
Jun 9, 2004
Messages
13,327
Code:
qd.Parameters![YourParm] = SomeValue

Never used this - Cool...

kh
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 02:45
Joined
Feb 19, 2002
Messages
43,565
Set qd = dbs.QueryDefs!qryQCMainSizeCheck
- assigns a query to the querydef object.
qd.Parameters![YourParm] = SomeValue
- assigns a value to the parameter in your query. Replace [YourParm] with whatever name you used for the parameter in the query. SomeValue is any valid expression that evaluates to the value you want to pass to the query.
Set rst = qd.OpenRecordset
- opens a recordset based on the query.

The quote is incorrect. Please post a link and I'll fix it.
Set rst = dbs.OpenRecordset
should be
Set rst = qd.OpenRecordset
 
Last edited:

Users who are viewing this thread

Top Bottom