I have an SQL statement in VBA and I am concatenating into it criteria from a combo box. The row source of the Combo Box is:
Code:
SELECT Categories.ID, Categories.Category FROM Categories UNION Select Null as AllChoice , "(All)" as Bogus From Categories
ORDER BY Categories.Category;
The purpose of All is to be able to choose All Categories as a criteria for the query. This works when I run the query in Access.
For my next application, I am forced to convert this query into VBA code with an SQL statement. The chunk of the VB statement giving me issues is:
Code:
WHERE (((Categories.ID) = " & [Forms]![frmCreateTriviaNight]![cboCategory1] & ")) Or (((" & [Forms]![frmCreateTriviaNight]![cboCategory1] & ") Is Null))
The VBA version of this query works fine when I have a specific Category chosen. For example if Category 22 is chosen then the statement becomes:
Code:
WHERE (((Categories.ID) = 22)) Or (((22) Is Null))
which works. But if the Category combo box has (All) selected, then the statement becomes:
Code:
WHERE (((Categories.ID) = )) Or ((() Is Null))
Which throws an error for invalid syntax. How can I deal with this null value in my VBA code?