Too few parameters error

P

palazo3

I must be having a brainfart...for the life of me, I can't figure what
I am doing wrong here:

I want to run a query and have the total number of records returned
stored in a variable.

Dim db As Database
Dim rs As Recordset
Dim totalcount As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("Select count(*) as x from
qryServiceALLqb WHERE [TYPEREC?] = 'HA'")
totalcount = rs!x
MsgBox mcount


The error I keep getting is too few parameters. Expected 2.
Runtime Error: 3061

Any suggestions?
 
S

strive4peace

Error handler
---


perhaps your recordset is not returning any records...

is this the line that causes the problem:
totalcount = rs!x

if so, that is the case

paste the SQL statement (without the quote marks around it) into the SQL
view of a query, then click on the Datasheet view icon and see if any
records are returned.

~~~

To see which statement is causing the problem, add an error handler to
your code

ERROR HANDLER CODE:

put this at the top of your program, right after the procedure
declaration (skip a line first for better readability)

'~~~~~~~~~~~~~~~~~~~~~~
'set up Error Handler
On Error GoTo Proc_Err
'~~~~~~~~~~~~~~~~~~~~~~
... then your statements
'~~~~~~~~~~~~~~~~~~~~~~

put this at the end of the program

'~~~~~~~~~~~~~~~~~~~~~~
Proc_Exit:
On Error Resume Next
'release object variables if any
Exit Function 'or Exit Sub

Proc_Err:
MsgBox Err.Description, , _
"ERROR " & Err.Number _
& " ProcedureName"

'press F8 to step through code and debug
'remove next line after debugged
Stop: Resume

Proc_Exit
'~~~~~~~~~~~~~~~~~~~~~~

where
ProcedureName is the name of your procedure so you can identify what
code the problem is in when you see the error

While I am developing, I like to make the error handler go to the line
that caused the problem so I can see where it is. Stop will stop the
code and Resume goes back to the offending line. When code Stops, press
F8 to execute one statement at a time.

The line labels do not matter (Proc_Exit:, Proc_Err:), I like to use the
same ones all the time -- they only have to be unique within a procedure.



Warm Regards,
Crystal
*
:) have an awesome day :)
*
MVP Access
Remote Programming and Training
strive4peace2006 at yahoo.com
*
 
D

Douglas J. Steele

Try changing

Dim rs As Recordset

to

Dim rs As DAO.Recordset

When you have references set to both ADO and DAO, you'll find that you'll
need to "disambiguate" certain declarations, because objects with the same
names exist in the 2 models. For example, to ensure that you get a DAO
recordset, you'll need to use Dim rsCurr as DAO.Recordset (to guarantee an
ADO recordset, you'd use Dim rsCurr As ADODB.Recordset)

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset
 
R

Rick Brandt

I must be having a brainfart...for the life of me, I can't figure what
I am doing wrong here:

I want to run a query and have the total number of records returned
stored in a variable.

Dim db As Database
Dim rs As Recordset
Dim totalcount As Integer
Set db = CurrentDb
Set rs = db.OpenRecordset("Select count(*) as x from
qryServiceALLqb WHERE [TYPEREC?] = 'HA'")
totalcount = rs!x
MsgBox mcount


The error I keep getting is too few parameters. Expected 2.
Runtime Error: 3061

Any suggestions?

Does qryServiceALLqb contain any parameters? Those need to be explicitly
declared if you use the query from code like that. When you run the query in
the Access GUI the expression service resolves parameters for you automatically.
When used as you are doing in code the expression service is not in play.
 

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