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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I'm trying to use VB6 to access an Access 2000 query? 1

Status
Not open for further replies.

adamtate

Technical User
Dec 18, 2002
23
GB
OK i think i'm nearly there...

this is my code:

Private Sub Command1_Click()

Dim db As Database
Dim rs As Recordset
Dim fld As Field

Set db = DBEngine.OpenDatabase("h:\cruisetools.mdb")
Set rs = db.OpenRecordset("Product List Search by Product Code")

End Sub

I'm getting a runtime error. Too few parameters. Expected 1.

Can anyone tell me why this is happening? Apparently it's something to do with the SET RS=..... line of code.

PLEASE HELP... IT'S HURTING MY HEAD!

 
You can't open a query as a recordset if the query has criteria that the code isn't aware of. It sounds like that is what you have. You can do one of two things that I know of.

1. Instead of calling the Access query in the OPENRECORDSET method, use an SQL string to do the same thing. You can see the SQL version of the Access query in VIEW -> SQL View. That could be cut and pasted into the OPENRECORDSET method, with a few character modifications (' instead of ", for instance)

2. Identify the criteria using a QueryDef variable type. Something like this:
..........................................................
Private Sub Command1_Click()

Dim db As Database
Dim rs As Recordset
Dim fld As Field
DIM qdefSOLUTION as QUERYDEF

Set db = DBEngine.OpenDatabase("h:\cruisetools.mdb")
Set qdfSOLUTION = db.QueryDefs("Product List Search by Product Code")
qdfSOLUTION![CRITERIA YOU ARE USING] = [CRITERIA YOU ARE USING]
Set rs = qdfSOLUTION.OPENRECORDSET()
..........................................................


Good luck
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top