Creating A Recordset from a parameter query

G

Guest

I have created a query (qryMO_ProductionDaily) that uses the following
statement to choose data according to date:
Between [Forms]![frmDatesAndReportTitles]![txtDatePeriodStart] And
[Forms]![frmDatesAndReportTitles]![txtDatePeriodEnd]

This works quite nicely normally, (the form containing the dates is already
loaded) however, when I try to create a Recordset as follows:

Dim dbs As DAO.Database
Dim rstDailyProduction As DAO.Recordset

Set dbs = CurrentDb()
Set rstDailyProduction = dbs.OpenRecordset("qryMO_ProductionDaily")

I get the following error:
Error #: 3061
Too few parameters. Expected 2

How do I resolve this?

Thanks in advance for any help!
 
M

Marshall Barton

KlondikeMiner said:
I have created a query (qryMO_ProductionDaily) that uses the following
statement to choose data according to date:
Between [Forms]![frmDatesAndReportTitles]![txtDatePeriodStart] And
[Forms]![frmDatesAndReportTitles]![txtDatePeriodEnd]

This works quite nicely normally, (the form containing the dates is already
loaded) however, when I try to create a Recordset as follows:

Dim dbs As DAO.Database
Dim rstDailyProduction As DAO.Recordset

Set dbs = CurrentDb()
Set rstDailyProduction = dbs.OpenRecordset("qryMO_ProductionDaily")

I get the following error:
Error #: 3061
Too few parameters. Expected 2


Access takes care of those things for you in the UI, but in
VBA code you have to do it yourself:

Dim qdf As QueryDef
Dim prm As Parameter
Set qdf = dbs.QueryDefs!qryMO_ProductionDaily
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rstDailyProduction = qdf.OpenRecordset()
 
G

Guest

Thanks for the help. However, just after I posted my question, I found the
answer to the problem under "access.modulesdaovba", but after trying the
solution, I was not able to get back into the forum (for some goofy reason)
and let people know.


Marshall Barton said:
KlondikeMiner said:
I have created a query (qryMO_ProductionDaily) that uses the following
statement to choose data according to date:
Between [Forms]![frmDatesAndReportTitles]![txtDatePeriodStart] And
[Forms]![frmDatesAndReportTitles]![txtDatePeriodEnd]

This works quite nicely normally, (the form containing the dates is already
loaded) however, when I try to create a Recordset as follows:

Dim dbs As DAO.Database
Dim rstDailyProduction As DAO.Recordset

Set dbs = CurrentDb()
Set rstDailyProduction = dbs.OpenRecordset("qryMO_ProductionDaily")

I get the following error:
Error #: 3061
Too few parameters. Expected 2


Access takes care of those things for you in the UI, but in
VBA code you have to do it yourself:

Dim qdf As QueryDef
Dim prm As Parameter
Set qdf = dbs.QueryDefs!qryMO_ProductionDaily
For Each prm In qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm
Set rstDailyProduction = qdf.OpenRecordset()
 

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