Running criteria query using ADO in form causes error

J

Julia Boswell

Hi all,

I've searched and haven't found a response on this one, so I wonder if you
can help.

I've got a criteria query called qryFindTrainingDue which looks as follows:

SELECT tblTestTrainingDue.Employee, tblTestTrainingDue.TestTrainingDue
FROM tblTestTrainingDue
WHERE
(((tblTestTrainingDue.TestTrainingDue)=[Forms]![frmMultipleEntry]![txtTraining]));

It works fine.

I'm trying to open it as a recordset to search through using ADO in an
unbound form (frmMultipleEntry). The code is as follows:

Dim db As ADODB.Connection
Dim rsDue As New ADODB.Recordset
Set db = CurrentProject.Connection
rsDue.Open "qryFindTrainingDue", db, adOpenKeyset, adLockOptimistic

When the code runs, I get the error message -2147217900 Invalid SQL
Statement, expected DELETE, INSERT, PROCEDURE, SELECT or UPDATE.

Can anyone give me any clues where I'm going wrong?

Thanks

Julia
 
J

Julia Boswell

Hi all,

Found a way round this, not using an access query as follows:

Dim intParam As Integer
Dim strDue As String

intParam = [Forms]![frmMultipleEntry]![txtTraining]
strDue = "SELECT * FROM tblTestTrainingDue WHERE TestTrainingDue = " &
intParam

rsDue.Open strDue, db, adOpenKeyset, adLockOptimistic, adCmdTableDirect

This works fine.

Julia
 

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