is it possible to change the query criteria with VBA?

  • Thread starter Thread starter rmd
  • Start date Start date
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
 
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
 
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
 

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

Back
Top