Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using recordset to open query with parameter 1

Status
Not open for further replies.

hegartyjp

Programmer
Jun 16, 2004
57
US
Hi all.

I am having a problem with a very simple piece of work. I cannot ever remeber there being an issue with this before.

I have a form which has a textfield which has a date in it.

I have a Select query that selects from a simple table all records that match the date that is in the textfield.

In my code, I want to open this query to see if there are any records.

So I have:

Dim currentquery As String
Dim DB As Database
Dim rec As Recordset

currentquery = "Qry_CheckQuarterEnd"


Set DB = CurrentDb()
Set rec = DB.OpenRecordset(currentquery)



If rec.EOF = True Then
MsgBox "Empty"
Else
rec.MoveLast
MsgBox rec.RecordCount
End If

rec.Close




However, when I try to run this I get the error:

Run Time error 3061
Too few parameters. Expected 1.

Can anyone tell me why I am getting this error.


Many thanks in advance

JP
 
does the query require a parameter ?
which line does it bug out on ?

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
it bugs on:

Set rec = DB.OpenRecordset(currentquery)

Yeah, the query needs the date parameter as it is dependant on the date on the form.

Thanks

JP
 
You may try this simple line:
MsgBox DCount("*", "Qry_CheckQuarterEnd") & " row(s)"

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Well if it needs a parameter and you are not passing it one, you're going to have a problem....

This link has a couple of examples:


Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Geoff. Thanks for your replies. The parameter is being pulled in by the query from the form so I thought it should work. It works if you were just to run query manually.

Anyway that line of code from PHV (PH) works a treat. Never saw that before.

Thanks very much.

I am sorted

Thanks again to you both...

JP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top