Create Recordset in VBA

G

George

I've got a form called XYZ that has a record ID in one of the fields,
[BKWakeREID],on the form. I want to open a related database, called GES,
and create a temp recordset from GES using the following code. The XYZ form
is open and the following code is executed under a command button click sub.
The control named BKWakeREID contains the pointer to the records in GES.

Dim RS As DAO.Recordset, myCaseID As String, db As DAO.Database
Dim stDocName As String, stLinkCriteria As String, mySQL As String
Set db = CurrentDb()
mySQL = "SELECT GES.* FROM GES WHERE GES.Account = me![BKWakeREID]"
Set RS = DBEngine(0)(0).OpenRecordset (mySQL, dbOpenDynaset)

I'm getting an error when I execute the openrecordset command of "Too few
parameters, Expected 1"

Could someone suggest the correct syntax to fix this?
 
D

Dirk Goldgar

George said:
I've got a form called XYZ that has a record ID in one of the fields,
[BKWakeREID],on the form. I want to open a related database, called GES,
and create a temp recordset from GES using the following code. The XYZ
form is open and the following code is executed under a command button
click sub. The control named BKWakeREID contains the pointer to the
records in GES.

Dim RS As DAO.Recordset, myCaseID As String, db As DAO.Database
Dim stDocName As String, stLinkCriteria As String, mySQL As String
Set db = CurrentDb()
mySQL = "SELECT GES.* FROM GES WHERE GES.Account = me![BKWakeREID]"
Set RS = DBEngine(0)(0).OpenRecordset (mySQL, dbOpenDynaset)

I'm getting an error when I execute the openrecordset command of "Too few
parameters, Expected 1"

Could someone suggest the correct syntax to fix this?


You need to take me![BKWakeREID] out of the string, and just append its
value on the end:

mySQL = "SELECT GES.* FROM GES WHERE GES.Account = " & Me![BKWakeREID]

If Account is a text field, you'll also need to embed quotes around the
value:

mySQL = "SELECT GES.* FROM GES WHERE GES.Account = '" & _
Me![BKWakeREID] & "'"
 

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