Recordset problem

S

Steven

I am trying to open a recordset that is a query. The query is saved as
"qDepositSlip". The query has 6 fileds and 3 fileds where the criteria is
based on textboxes in a form. In the Criteria of the query for those 3
fields it has [Forms]![NameOfForm]![NameOfTextbox]. The problem is that when
I try to say

Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("qDepositSlip")

It tells me Too few parameters. Expected 3.

How do I fix this?

Thank you,


Steven
 
M

Marshall Barton

Steven said:
I am trying to open a recordset that is a query. The query is saved as
"qDepositSlip". The query has 6 fileds and 3 fileds where the criteria is
based on textboxes in a form. In the Criteria of the query for those 3
fields it has [Forms]![NameOfForm]![NameOfTextbox]. The problem is that when
I try to say

Dim db As Database
Dim rs As Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("qDepositSlip")

It tells me Too few parameters. Expected 3.


Dim db As Daatbase
Dim qdf As QueryDef
Dim prm As Parameter
Dim rs As Recordset

Set db = CurrentDb()
Set qdf = db.QueryDefs!qDepositSlip

For Each prm In qdf.Parameters
prm = Eval(prm.Name)
Next prm

Set rs = qdf.OpenRecordset()
. . .

rs.Close : Set rs = Nothing
Set qdf = Nothing
Set db = Nothing
 
O

OssieMac

Hi Steven,

Try the following.

In the VBA editor select menu item Tools -> References and then scroll down
to Microsoft DAO 3.6 Object Library and check the box (Ensure you check the
box not just select the line) then click OK.

Then try the following code. I have included a sample for reading and
writing to the fields.

Dim db As DAO.database
Dim rs As DAO.Recordset
Set db = CurrentDb()
Set rs = db.OpenRecordset("qDepositSlip")

'Additional information on reading and writing to the fields
'Note the field index number can be replaced with the
'literal name in double quotes. eg .Fields("MyField")
With rs
.MoveFirst
Do While Not .EOF
'Reading value of fields
MsgBox .Fields(1)
MsgBox .Fields(2)

'Writing a value to fields
.Edit
.Fields(3) = "My New field 3 value"
.Fields(4) = "My New field 4 value"
.Update
.MoveNext
Loop
End With
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top