Runtime Error 3061. Too Few Parameters. Expected 8.

M

michael c

I have a module on my form that sends emails. The code
gets caught up at "Set rs = db.Open..." and the error
is "Runtime Error 3061. Too Few Parameters. Expected 8."
I'm not really sure why I have to define parameters or how
to do so. The code works fine for other queries. Any
thoughts would be great. Thanks!!

If Me.Clock = Me!SENDENDOEAST Then

Set db = CurrentDb

Set rs = db.OpenRecordset("SELECT * " & _
"FROM [qryManagement]" & _
"WHERE [Product]='Cola'")

LBDValue = rs![LBDDollarsShipped]
MTDValue = rs![MTDDollarsShipped]
QTDValue = rs![QTDDollarsShipped]

MTDValuePlan = rs![MTDPlan]
QTDValuePlan = rs![QTDPlan]

MTDPercPlan = (MTDValue / MTDValuePlan) -
Me!PercentOfMonth
QTDPercPlan = (QTDValue / QTDValuePlan) -
Me!PercentOfQuarter

DaysOfMonth = Me!CurrentDay & " of " & Me!DaysThisMonth
DaysOfQuarter = Me!QuarterWorkDaysToDate & " of " & Me!
QuarterWorkingDays

LBDText = "LBD:" & Format(Val(Str([LBDValue])), "#,###")
MTDText = "MTD:" & Format(Val(Str([MTDValue])), "#,###")
& "(" & Format(Val([MTDPercPlan]) * 100, "##.0\%") & ")"
QTDText = "QTD:" & Format(Val(Str([QTDValue])), "#,###")
& "(" & Format(Val([QTDPercPlan]) * 100, "##.0\%") & ")"

Msg = LBDText & vbCrLf & MTDText & vbCrLf & QTDText

....

End If
 
R

Ronald Dodge

Normally speaking, you would want to declare the various arguments. I in
particularly do this as I don't like to leave things up to chance that the
code may go in a direction that I may not have expected, or possibly create
some other wierd situation by not properly defining the objects/variables.

Questions you should ask yourself:

What is the purpose of the recordset?
What do I need for the recordset?
Do I need to have the recordset manipulated (adding/updating/deleting
records)
What criteria(s) do I need to use to filter the recordset?
Do I need to allow the recordset see changes as the data behind the scene is
modified?
If I need to have the data editable, do I want record level locking during
edit times?

The above are just a few of the questions that you should ask yourself, but
the answers to these types of questions are what's going to determine how
you should fill in the arguments of the methods you are calling on.

Example:

If you want a recordset with the above criteria, you need to be able to edit
the data, and you also need to be able to see the changes, but must have
record level locking to prevent 2+ users trying to edit the same record, you
would use the following code:

Set rs = db.OpenRecordset("SELECT * " & _
"FROM [qryManagement]" & _
"WHERE [Product]='Cola'", & _
dbOpenDynaset, dbSeeChanges, & _
dbPessimistic)

In this case, you may even need to run the Requery on the underlining query,
then create this recordset (or requery if recordset already created).
--
Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000

michael c said:
I have a module on my form that sends emails. The code
gets caught up at "Set rs = db.Open..." and the error
is "Runtime Error 3061. Too Few Parameters. Expected 8."
I'm not really sure why I have to define parameters or how
to do so. The code works fine for other queries. Any
thoughts would be great. Thanks!!

If Me.Clock = Me!SENDENDOEAST Then

Set db = CurrentDb

Set rs = db.OpenRecordset("SELECT * " & _
"FROM [qryManagement]" & _
"WHERE [Product]='Cola'")

LBDValue = rs![LBDDollarsShipped]
MTDValue = rs![MTDDollarsShipped]
QTDValue = rs![QTDDollarsShipped]

MTDValuePlan = rs![MTDPlan]
QTDValuePlan = rs![QTDPlan]

MTDPercPlan = (MTDValue / MTDValuePlan) -
Me!PercentOfMonth
QTDPercPlan = (QTDValue / QTDValuePlan) -
Me!PercentOfQuarter

DaysOfMonth = Me!CurrentDay & " of " & Me!DaysThisMonth
DaysOfQuarter = Me!QuarterWorkDaysToDate & " of " & Me!
QuarterWorkingDays

LBDText = "LBD:" & Format(Val(Str([LBDValue])), "#,###")
MTDText = "MTD:" & Format(Val(Str([MTDValue])), "#,###")
& "(" & Format(Val([MTDPercPlan]) * 100, "##.0\%") & ")"
QTDText = "QTD:" & Format(Val(Str([QTDValue])), "#,###")
& "(" & Format(Val([QTDPercPlan]) * 100, "##.0\%") & ")"

Msg = LBDText & vbCrLf & MTDText & vbCrLf & QTDText

...

End If
 
D

Dirk Goldgar

michael c said:
I have a module on my form that sends emails. The code
gets caught up at "Set rs = db.Open..." and the error
is "Runtime Error 3061. Too Few Parameters. Expected 8."
I'm not really sure why I have to define parameters or how
to do so. The code works fine for other queries. Any
thoughts would be great. Thanks!!

If Me.Clock = Me!SENDENDOEAST Then

Set db = CurrentDb

Set rs = db.OpenRecordset("SELECT * " & _
"FROM [qryManagement]" & _
"WHERE [Product]='Cola'")

LBDValue = rs![LBDDollarsShipped]
MTDValue = rs![MTDDollarsShipped]
QTDValue = rs![QTDDollarsShipped]

MTDValuePlan = rs![MTDPlan]
QTDValuePlan = rs![QTDPlan]

MTDPercPlan = (MTDValue / MTDValuePlan) -
Me!PercentOfMonth
QTDPercPlan = (QTDValue / QTDValuePlan) -
Me!PercentOfQuarter

DaysOfMonth = Me!CurrentDay & " of " & Me!DaysThisMonth
DaysOfQuarter = Me!QuarterWorkDaysToDate & " of " & Me!
QuarterWorkingDays

LBDText = "LBD:" & Format(Val(Str([LBDValue])), "#,###")
MTDText = "MTD:" & Format(Val(Str([MTDValue])), "#,###")
& "(" & Format(Val([MTDPercPlan]) * 100, "##.0\%") & ")"
QTDText = "QTD:" & Format(Val(Str([QTDValue])), "#,###")
& "(" & Format(Val([QTDPercPlan]) * 100, "##.0\%") & ")"

Msg = LBDText & vbCrLf & MTDText & vbCrLf & QTDText

...

End If

Does the query "qryManagement" include references to controls on forms,
possibly in the WHERE criteria? If so, those references constitute
parameters as far as DAO is concerned, and must be filled in. You could
do this by way of a QueryDef object:

Dim qdf As DAO.QueryDef
Dim prm As DAO.Parameter

Set qdf = db.CreateQueryDef( , _
"SELECT * FROM qryManagement " & _
"WHERE [Product]='Cola'")

For each prm in qdf.Parameters
prm.Value = Eval(prm.Name)
Next prm

Set rs = qdf.OpenRecordset

' ... code using recordset ...

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

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