Filter for yes/no

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello all,

I created a form to function as a filter to run a report. One of the
criteria is a yes/no check box. I don't know how to write a if/then
statement like a text box below.

If Not IsNull(Me.txtBox) Then
strWhere = strWhere & "([Contents] Like ""*" & Me.txtBox & "*"") AND "
End If

Please help me with a similar code for the yes/no check box.

Thanks.
 
Hello all,

I created a form to function as a filter to run a report. One of the
criteria is a yes/no check box. I don't know how to write a if/then
statement like a text box below.

If Not IsNull(Me.txtBox) Then
strWhere = strWhere & "([Contents] Like ""*" & Me.txtBox & "*"") AND "
End If

Please help me with a similar code for the yes/no check box.

Thanks.

A checked checkbox has the value -1; the word True (without quotes) is a
synonym for that value. False and 0 are similarly synonymous.

Since an IF statement branches on a true or false value, you can simply
reference the control:

strWhere = strWhere & "([YesNoField] = " & Me!chkMyCheckbox)


John W. Vinson [MVP]
 
Good morning John,

Thanks for your help. I tried the code below, and I got an error message
"Compile error: Expected: end of statement". Am I missing something?

If Me.chkOut = True Then
strWhere = strWhere & "([Out?] = " & me.chkOut) and "
End If

Thanks.

John W. Vinson said:
Hello all,

I created a form to function as a filter to run a report. One of the
criteria is a yes/no check box. I don't know how to write a if/then
statement like a text box below.

If Not IsNull(Me.txtBox) Then
strWhere = strWhere & "([Contents] Like ""*" & Me.txtBox & "*"") AND "
End If

Please help me with a similar code for the yes/no check box.

Thanks.

A checked checkbox has the value -1; the word True (without quotes) is a
synonym for that value. False and 0 are similarly synonymous.

Since an IF statement branches on a true or false value, you can simply
reference the control:

strWhere = strWhere & "([YesNoField] = " & Me!chkMyCheckbox)


John W. Vinson [MVP]
 
Good morning John,

Thanks for your help. I tried the code below, and I got an error message
"Compile error: Expected: end of statement". Am I missing something?

If Me.chkOut = True Then
strWhere = strWhere & "([Out?] = " & me.chkOut) and "
End If

A quote. The closing parenthesis and the word "and" are not being included in
the text string you're building.

When you're assembling a text string from pieces, you need to identify each
"chunk" that goes into the string. Some chunks will be literal text enclosed
in quotes; some will be variables; some may be form references. The three
pieces that you need to assemble here are the literal text string

"([Out?] = "

the value of the the checkbox, -1 or 0;

and a literal text string

") and"

Try

strWhere = strWhere & "([Out?] = " & me.chkOut & ") and "

which should append somthing like

([Out?] = -1) and

to the growing strWhere.

John W. Vinson [MVP]
 
Hi John,

Thank you very much for your helps and taking the time to explain to me the
pieces. It works out perfectly.

Can I ask you something? I don't know I should ask you this. I am just
curious. Access geniuses like yourself and others in this Microsoft
discussion group, do you guys get paid from Microsoft? Or you guys just
enjoy helping out?

Thanks.

John W. Vinson said:
Good morning John,

Thanks for your help. I tried the code below, and I got an error message
"Compile error: Expected: end of statement". Am I missing something?

If Me.chkOut = True Then
strWhere = strWhere & "([Out?] = " & me.chkOut) and "
End If

A quote. The closing parenthesis and the word "and" are not being included in
the text string you're building.

When you're assembling a text string from pieces, you need to identify each
"chunk" that goes into the string. Some chunks will be literal text enclosed
in quotes; some will be variables; some may be form references. The three
pieces that you need to assemble here are the literal text string

"([Out?] = "

the value of the the checkbox, -1 or 0;

and a literal text string

") and"

Try

strWhere = strWhere & "([Out?] = " & me.chkOut & ") and "

which should append somthing like

([Out?] = -1) and

to the growing strWhere.

John W. Vinson [MVP]
 
Can I ask you something? I don't know I should ask you this. I am just
curious. Access geniuses like yourself and others in this Microsoft
discussion group, do you guys get paid from Microsoft? Or you guys just
enjoy helping out?

I'm a self-employed semi-retired consultant, living in my home in Idaho and
helping my wife with her farmers' market business. I'm not a Microsoft
employee and am not paid by MS, or by anyone else, for volunteering my time
here. I just am "paying back" for all the help many others gave me along the
way; I learn a lot from answering interesting questions (if I don't know the
answer I'm spurred to find out, or I watch to see if one of the many other
experts has an answer at hand which I haven't seen before).

Microsoft does recognize frequent and accurate answer-posters with their "MVP"
- Most Valuable Professional - program. See

http://mvp.support.microsoft.com/default.aspx

for a description of the program and a link to a list of those MVP's who want
their names made public. I'm proud to have been a MVP for several years now...
and embarrased to not recall offhand how many!

John W. Vinson [MVP]
 
Back
Top