0
votes

I have 3 combobox to filter data, then i want to open in command button to print preview.. Problems I have if i used 2 combobox it works but when i used three combobox the report is blank...there's any problems with the code?? here's the code i used :

Dim strWhereCondition As String
strWhereCondition = "[month] = '" & Me.cbmonth.Value _
                    & "' and [Works] = '" & Me.cbwork.Value _
                    & "' and [Works] = '" & Me.cbwork2.Value & "'"

Debug.Print strWhereCondition
DoCmd.OpenReport "Month List", View:=acViewPreview, _
WhereCondition:=strWhereCondition

and the requery for my form

SELECT *
FROM MyTable 
WHERE (month = Forms!nameForm!cbmonth
OR Forms!MeForm!cbwork IS NULL)
And (works = Forms!nameForm!cbwork
OR Forms!nameForm!cbwork IS NULL)
AND (works = Forms!nameForm!cbwork2
OR Forms!nameForm!cbwork2 IS NULL);

can anyone help?

1

1 Answers

-1
votes

Month is a number, so try:

strWhereCondition = "[month] = " & Me.cbmonth.Value _
                & " and [Works] = '" & Me.cbwork.Value _
                & "' and [Works] = '" & Me.cbwork2.Value & "'"

Edit: Month is text.

However, [Work] is supposed to match two potentially different values:

& "' and [Works] = '" & Me.cbwork.Value _
& "' and [Works] = '" & Me.cbwork2.Value & "'"

Should most likely be:

& "' and [Works] = '" & Me.cbwork.Value _
& "' and [SomeOtherField] = '" & Me.cbwork2.Value & "'"