Filter subform by months using combobox

guestbb

Registered User.
Local time
Today, 13:42
Joined
Jul 14, 2015
Messages
44
I made a subform based of a query that I put in a main form. The subform contains a date field, where a full date is inserted (example 24.12.2015.). What I am doing is making a form where the subform would be filtered by a combobox by months. This may be wrong (correct me if it is), but for values in the combobox I placed number from 1 to 12 (as months). This combobox would then only show records from that month.
I used a Change function in VBA on the combobox but I keep getting an error.

This is the VBA on the combobox where I change the record source of the subform. I probably made the WHERE part wrong but dont know how to fix it.

Combobox name is cboMonth.
Field where the full date is, is DateOut.
Subform is called subCustomer.

Code:
Private Sub cboMonth_Change()
Dim SQL As String

SQL = "SELECT qryCustomers.SID, qryCustomers.KID, qryCustomers.MMT, " _
    & "qryCustomers.Owner, qryCustomers.User, qryCustomers.Policy, " _
    & "qryCustomers.DateOut " _
    & "FROM qryCustomers " _
    & "WHERE Month([DateOut]) LIKE '*" & Me.cboMonth.Text & "*'"

    Me.subCustomer.Form.RecordSource = SQL
    Me.subCustomer.Form.Requery
End Sub
 
What is the Error, Error Number, Error Description. When does the error occur.

Goh
 
It opens the popup and asks me to insert the value of DateOut. Then when I enter it it asks again. And in the background the subform is empty.
 
Code:
"WHERE Month([DateOut]) LIKE '*" & Me.cboMonth.Text & "*'"
Month returns a number, better not use like...
The current statement if you put in 1 into the combo you will also return 10,11 and 12...

Better would be
Code:
"WHERE Month([DateOut]) =" & Me.cboMonth.Text & ""

Edit:
You may also want to consider what happens with Jan-2015, Jan-2016, Jan-2017, etc..
 

Users who are viewing this thread

Back
Top Bottom