PDA

View Full Version : [SOLVED:] Filter problem in subform



TonC
01-30-2016, 02:40 AM
Hello,

I've got the following problem with a month filter in my subformRO.:banghead:
In my headform, there is a combobox named "cmbMaand" That combo has its rowsource form a query. And a group by . This queryfield is not in a table.

Format([Datum];"mmm") is the expression in the query.
When I click on the combobox in my headform it shows me the short names of the month, such as
jan, feb, mrt, etc. etc. So far so good.

In my subformRO there is a field named "maand", they shows me all the month names who is related to the field "Datum" (see my query expression)

What I would like to do is obvious, select a month in my combobox, and then filter only the records named in the combobox in my subformRO.

Perhaps there are several ways to do so, or maybe another approach for making the filter.
Here is my code:


Private Sub btnFilter_Click()
Dim db As DAO.Database

Dim strWhere As String 'The criteria string.
Dim lngLen As Long 'Length of the criteria string to append to.

If Not IsNull(Me.cmbMaand) Then
strWhere = strWhere & "([Maand] = " & Me.cmbMaand & ") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
msgbox "No criteria", vbInformation, "Nothing to do."
Else
strWhere = Left$(strWhere, lngLen)

Me.subfrmRO.Form.Filter = strWhere
Me.subfrmRO.Form.FilterOn = True '(******)

End If

End Sub

'(******) In the last rule of my code, vba gives my an error

What goes wrong? Please try to help.

Thanks in advance.

jonh
01-30-2016, 03:57 AM
put single quotes around the value

subfrmRO.Form.Filter = "[Maand] = '" & cmbMaand & "'"
subfrmRO.Form.FilterOn = True

TonC
01-30-2016, 05:11 AM
john, its works. As usual, a very good help.
Many thanks,:beerchug: