Robert Kendall
Robert Kendall

Reputation: 390

Applying a filter to a form in MSAccess

IN MSAccess, I have a report which summarizes the records. I want to be able to click the 'Formdate" field on the report and open the corresponding record in a "MAF View" form.

The following code opens the "MAF View" form, but applies the filter to the report instead of the form. How do I apply the filter to the form instead?

Dim strFilter As Variant
strFilter = "[Formdate] = #" & Format(Me!FormDate.Value, "mm\/dd\/yyyy") & "#"
Me.Filter = strFilter
FilterOn = True
DoCmd.OpenForm "Maf View", , strFilter

Upvotes: 0

Views: 93

Answers (1)

Andre
Andre

Reputation: 27644

DoCmd.OpenForm(FormName, View, FilterName, WhereCondition, DataMode, WindowMode, OpenArgs)

You have strFilter in the FilterName argument instead of WhereCondition. A query name would go there, but not a SQL WHERE condition.

Either do

DoCmd.OpenForm "Maf View", , , strFilter

or - much better readable! - use named parameters:

DoCmd.OpenForm "Maf View", WhereCondition:=strFilter

Upvotes: 1

Related Questions