Too few Parameters, expected 1 err 3061

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm trying to run this code to set a form's recordsource. I've tried this
code both in the open and load events. intTot is actually a number field
whose format is byte. Am I missing a quote somewhere or what's wrong?

Thanks for all help offered!

JR
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("select * from tblTaxIndicators where intTot
= " & _
1, dbOpenSnapshot)

If rst.RecordCount = 1 Then
Me.RecordSource = "qryDD"
Else
Me.RecordSource = "qryDDTot"
End If

Set db = Nothing
Set rst = Nothing
 
Change Me.RecordSource = "qryDD" to Me.RecordSource =
CurrentDb.QueryDefs("qryDD")

Change the other statement similarly.
 
The previous answer is not the problem. It is a syntax error, I think.
Should be
Set rst = db.OpenRecordset("select * from tblTaxIndicators where intTot =
1;" , dbOpenSnapshot)

You would only need to move the 1 outside the qoutes if it were a variable
or control you were referencing, for example
x = 1
Set rst = db.OpenRecordset("select * from tblTaxIndicators where intTot = "
& x & ";" , dbOpenSnapshot)

Now, there is a simpler way to get what you want, I think. If you expect to
return either any record where intTot =1 or no records, then this approach
will work:

If IsNull(DLookup("[intTot]","tblTaxIndicators","[intTot] = 1")) Then
Me.RecordSource = "qryDDTot"
Else
Me.RecordSource = "qryDD"
End If
 
Another possibility is that your declaration of the recordset is incorrect.

Assuming you're using Access 2000 or 2002, you obviously have added a
reference to DAO, or else Dim db As Database would raise an error. However,
if you didn't remove the reference to ADO, your declaration for rst is
incorrect. If you have both references, 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 rst as DAO.Recordset (to guarantee an ADO recordset,
you'd use Dim rst As ADODB.Recordset) I have seen the "Too few parameters"
message under this condition.

The list of objects with the same names in the 2 models is Connection,
Error, Errors, Field, Fields, Parameter, Parameters, Property, Properties
and Recordset
 
Thanks to all who replied! Klatuu, that worked great! It will be a lot
easier to code than dealing with the query coding.

Thanks for your great advice!

JR
--
www.brightfuture.ca/bright
My email address can be found on my site.


Klatuu said:
The previous answer is not the problem. It is a syntax error, I think.
Should be
Set rst = db.OpenRecordset("select * from tblTaxIndicators where intTot =
1;" , dbOpenSnapshot)

You would only need to move the 1 outside the qoutes if it were a variable
or control you were referencing, for example
x = 1
Set rst = db.OpenRecordset("select * from tblTaxIndicators where intTot = "
& x & ";" , dbOpenSnapshot)

Now, there is a simpler way to get what you want, I think. If you expect to
return either any record where intTot =1 or no records, then this approach
will work:

If IsNull(DLookup("[intTot]","tblTaxIndicators","[intTot] = 1")) Then
Me.RecordSource = "qryDDTot"
Else
Me.RecordSource = "qryDD"
End If


Johnny Bright said:
I'm trying to run this code to set a form's recordsource. I've tried this
code both in the open and load events. intTot is actually a number field
whose format is byte. Am I missing a quote somewhere or what's wrong?

Thanks for all help offered!

JR
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("select * from tblTaxIndicators where intTot
= " & _
1, dbOpenSnapshot)

If rst.RecordCount = 1 Then
Me.RecordSource = "qryDD"
Else
Me.RecordSource = "qryDDTot"
End If

Set db = Nothing
Set rst = Nothing
 
Johnny,

Try the following code for your set recordset statement.

Set rst = db.OpenRecordset("select * from tblTaxIndicators where
intTot = 1", dbOpenSnapshot)

In essence, include the 1 inside the statement. If you wish to have
the criteria expressed as a variable, you would need it outside the
quotes, but as a literal, including it in the statement is the way to
go. This is a bit deceiving since 1 is an int vs. a string.

Hope this helps,
Kevin


Johnny said:
I'm trying to run this code to set a form's recordsource. I've tried
this code both in the open and load events. intTot is actually a
number field whose format is byte. Am I missing a quote somewhere or
what's wrong?

Thanks for all help offered!

JR
Dim db As Database
Dim rst As Recordset

Set db = CurrentDb()
Set rst = db.OpenRecordset("select * from tblTaxIndicators where
intTot = " & _
1, dbOpenSnapshot)

If rst.RecordCount = 1 Then
Me.RecordSource = "qryDD"
Else
Me.RecordSource = "qryDDTot"
End If

Set db = Nothing
Set rst = 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

Back
Top