Dynamic Query

G

Guest

I'm trying to change the users criteria based on a set of checkboxes. But
first I wanted to test just being able to change the stored query behind a
form.


Dim db As DAO.Database 'DB Variable
Dim rst As DAO.Recordset 'Recordset
Dim qry As String

Dim qdf As DAO.QueryDef

Set db = CurrentDb
Set qdf = db.QueryDefs("str_Qry_Adj")

'Build the search query
qry = "SELECT * FROM Knowledge" & _
" WHERE (Data LIKE *" & "'" & Me.Keyword & "'*)"

qdf.SQL = qry


Apparantly there's a missing operator. If anyone could help me out I'd
appreciate it.
 
A

Andi Mayer

I'm trying to change the users criteria based on a set of checkboxes. But
first I wanted to test just being able to change the stored query behind a
form.


Dim db As DAO.Database 'DB Variable
Dim rst As DAO.Recordset 'Recordset
Dim qry As String

Dim qdf As DAO.QueryDef

Set db = CurrentDb
Set qdf = db.QueryDefs("str_Qry_Adj")

'Build the search query
qry = "SELECT * FROM Knowledge" & _
" WHERE (Data LIKE *" & "'" & Me.Keyword & "'*)"

qdf.SQL = qry


Apparantly there's a missing operator. If anyone could help me out I'd
appreciate it.

I don't tell you whats wrong, instead I will show you how to find it

Go to your code
set the cursor to: qdf.SQL = qry
press F9 (a breakpoint)
run the sub
in the immidiate window write: ?qry {Enter}
copy the query

create a query (Create a Query in Design View)
Goto SQl-View
Paste the copied query
goto Design View

AND watch what Access is telling you
 

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