setting the source or filter on the fly

G

Guest

I would like to know how i can set the filter on a report from a list of
criteria. I have created a report which is executed from a form where a user
can select different criteria. I would like to use the criteria selected as
the filter or maybe the source for the report. How can i past this info from
the form to the report's filter/source.

Thank you.

Andy
 
P

Pieter Wijnen

By Using The WhereCondition

Private Sub CmdReport_Click()
Dim MyFilter As String

MyFilter = "MyField1='" & Me.MyControl1.Value & "'" ' For Text Field
MyFilter = MyFilter & " AND MyField2=" &
Format(Me.MyControl2.Value,"\#yyyy-mm-dd\#") ' For Date Field
MyFilter = " AND MyField3=" & Me.MyControl3.Value ' For Numeric Field
MyFilter = " AND MyField4 Is Null" ' For Null Value, regardless of type

DoCmd.OpenReport "MyReport", acViewPreview, WhereCondition:=MyFilter

HtH

Pieter
 
G

Guest

Thank you, this is exactly what i was looking for.

Thank you for your help and time

Andy
 

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