Fil
Fil

Reputation: 471

How do you filter records from a union query using values from a combo box list?

I have a datasheet form frmDatasheet linked to a Query named qryAll. The datasheet form is a subform of frmMain form. In frmMain, I have a combo box named filterCombo. The filterCombo is suposed to make frmDatasheet display all records whos entryDate field is January, February and March only. I have used this method before with a table and it worked fine but doesn't seems to work on a union query.

My code is as follows:

Private Sub filterCombo_AfterUpdate()
Dim strSQL As String

strSQL = "SELECT * FROM qryAll WHERE MONTH(entryDate) = 1 OR MONTH(entryDate) = 2 OR MONTH(entryDate) = 3"
'Task2 = "SELECT * FROM qryAll WHERE MONTH(entryDate) = 1 OR 2 OR 3"

If Me.filterCombo.Value = "First quarter(Q1)" Then
Me.frmDatasheet.Form.RecordSource = strSQL
Exit Sub
End If
End Sub

Upvotes: 0

Views: 167

Answers (1)

June7
June7

Reputation: 21379

There is nothing wrong with your SQL syntax so explore other issues, such as misspelling.

Consider a simpler expression:

WHERE Month(entryDate) <= 3

Upvotes: 1

Related Questions