cmd button to open a form with a query

  • Thread starter Thread starter Fred
  • Start date Start date
F

Fred

Hi,

So my prob for now is :
I've made a button that open a form and show me some results. it's fine.
Now, I m doing another button that will open that form, but i want to filter
differents things.
I've made aquery for this, it works, but I dont know how to link the query
with that form and the button...


Thank you.
 
You don't really need the query, just its WHERE clause.
Use it to set the Filter property of the form.

Private Sub MyButton_Click()
Dim strWhere as String
strWhere = "[MyFieldName] Like '*Jones*'"
Me.Filter = strWhere
Me.FilterOn = True
End Sub


Good luck.
 
Hi,

So my prob for now is :
I've made a button that open a form and show me some results. it's fine.
Now, I m doing another button that will open that form, but i want to filter
differents things.
I've made aquery for this, it works, but I dont know how to link the query
with that form and the button...


Thank you.

Take a look at the help in the VBA editor for the "OpenForm Method".
There are two arguments to OpenForm - a WhereCondition and a Filter.
Either one will work.

Or, you can simply change the Recordsource property of the report to
the query that you have created.
 
Back
Top