is it possible to change the query criteria with VBA?

R

rmd

Hello All.

I currently have a form that I used Cmd buttons to change the query for the
forms record source. Each query has a criteria of 1 difference. Seems like a
lot of wasted space for the queries for 1 difference. I was just wondering
if it possible to change the query criteria with VBA? Like a click event to
the CmdButton.

Thanks
Bob
 
O

Ofer

Using VBA you can change the all SQL in your query, so yes you can change the
criteria

try this
Function FunctionName(NewCriteria as string)
Dim DBS As Database
Dim rst As Recordset, SqlStr As String

Set DBS = CodeDb
SqlStr = "SELECT * FROM TableName Where " & NewCriteria
DBS.QueryDefs("QueryName").SQL = SqlStr

End Function
 
L

Larry Daugherty

You might find it more convenient to select the criterion from a
combobox.

You could put

me.requerry

In the combobox's AfterUpdate event.

HTH
 
Top