Checkbox Query by Form (1 Viewer)

Cold Zero

New member
Local time
Today, 22:40
Joined
May 12, 2018
Messages
9
I have a query to be run by form that contain yes/no checkbox and cannot get it right to function.

I did all the combo and text boxes as explained in other thread

"I have a query that uses unbound text boxes and combo boxes on a form as criteria. But when I leave some of the boxes blank on the form, no records are returned by the query.

How do I make the query work when some of the boxes are empty?"

Here's a solution to the above question. You can open the main form in the example, enter or select some criteria, and click on the Search button to view the query results on the subform.

Basic Criteria Format
The example basically sets the criteria for each field in a separate column in the query grid like this in query Design view:-
-------------------------------------
Field: [FieldName]=[Forms]![FormName]![ControlName] or [Forms]![FormName]![ControlName] Is Null

Show: uncheck

Criteria: True
-------------------------------------
The [Forms]![FormName]![ControlName] Is Null enables us to leave the text box/combo box on the form blank. The True in the criteria row tells Access to treat the expression in the field row as the criteria.


Besides using the = operator in the expression for exact matches, we can also use other operators. For example, for partial matches of text strings, we can use:-

Field: [FieldName] Like "*" & [Forms]![FormName]![TextBoxName] & "*" or [Forms]![FormName]![TextBoxName] Is Null

In the example, I also included the using of an IIF expression as the criteria for the calculated Age field. When using an IIF expression as criteria, we can use the word True in the IIF to return all the records when the combo box or text box is left blank.

but couldn't find a way to do the checkboxes.
 

mike60smart

Registered User.
Local time
Today, 20:40
Joined
Aug 6, 2017
Messages
1,908
Hi

Are you able to upload a zipped copy of the Db?
 

essaytee

Need a good one-liner.
Local time
Tomorrow, 05:40
Joined
Oct 20, 2008
Messages
512
Hi

Are you able to upload a zipped copy of the Db?
I was thinking the same thing. I couldn't find something I could play around with to test.

I did find out that an unbound checkbox has three states, and is null on first opening. Once clicked though it's either true or false and the only way to get back to a null state is in code (unless there is some magic mouse trick available).
 

mike60smart

Registered User.
Local time
Today, 20:40
Joined
Aug 6, 2017
Messages
1,908
Hi

You can also use the following criteria to check:-

If Me.NameofCheckbox = -1 Then
strWhere = strWhere & "([NameofCheckbox] = True) AND "
ElseIf Me.NameofCheckbox = 0 Then
strWhere = strWhere & "([NameofCheckbox] = False) AND "
End If
 

Cold Zero

New member
Local time
Today, 22:40
Joined
May 12, 2018
Messages
9
I ended up ditching all the check boxes and replace them with combo boxes with YES/NO. check boxes created nothing but headaches for me.
 

Users who are viewing this thread

Top Bottom