Openning recordsets on queries

GaelicFatboy

Registered User.
Local time
Today, 22:43
Joined
Apr 17, 2007
Messages
100
I'm running into a bit of a problem when trying to open a recordset for a query. What I've got is a query referring to all fields in a single table with two filter criteria producing a single record from the tables data. The code I'm using is as follows:

Set My_DataBase = CurrentDb
Set My_RecordSet = My_DataBase.OpenRecordSet("My_Query", dbOpenDynaset) 'the code generates an error here
With My_RecordSet
.FindFirst "Category=""" & Combo_Category & """"
If Not .NoMatch Then
.Edit
![Discount] = Me.Text_Discount
.Update
.Close
End if
End With


What's going wrong is the second line of code produces an error as follows:

Error:3061, Too few parameters, expected 2.

The two filter criteria are for 'AccountNumber' and 'Category', with the two remaining fields being 'Discount' and DiscountType'.

I'm guessing the error has something to do with the two filter criteria, but I've tried a few variations without success.

Is anyone able to shed some light?

Cheers

D
 
change your code to
Code:
Set My_DataBase = CurrentDb
[COLOR="Red"]Set My_QueryDef =  My_DataBase.QueryDefs("My_Query")
My_QueryDef.Parameter("YourParametername") = "Some name of number"[/COLOR]
Set My_RecordSet = My_DataBase.OpenRecordSet("My_Query", dbOpenDynaset) 'the code generates an error here
With My_RecordSet
.FindFirst "Category=""" & Combo_Category & """"
If Not .NoMatch Then
.Edit
![Discount] = Me.Text_Discount
.Update
.Close
End if
End With
if you're not aware that you are using parameters, then you might have typed something wrong.

In your immediate window:
Code:
?currentdb.querydefs("My_Query").Parameter.Count
Will give you the number of Typo's:D
Code:
?currentdb.querydefs("My_Query").Parameter(0).name
Will give you the name of the typo!
 
Cheers for that I should be able to get things running now.

D
 
Guus2005,

What's the make and model of the bike in your signature, I'm looking to buy a new one later this year and it looks similar to one that caught my eye the other day.

If prefer to reply via e-mail then I'm on denis.mccrohan@gmx.com

Cheers mucker

D
 
It's a Yamaha Fazer 600 (FZ6 SA ABS 2007)
It is fast but not aggressive:D
 
I thought it looked like a Yamaha, I guess I've got a hard summer test riding ahead of me, what a shame.

Cheers

D
 

Users who are viewing this thread

Back
Top Bottom