Need help to see if this can be done

  • Thread starter Afrosheen via AccessMonster.com
  • Start date
A

Afrosheen via AccessMonster.com

I have a table with at least three fields that I need to create a filter for.
Here is the code:

strWhere = "tblTaps.WorkPlan=""" & Me.Combo149 & _
""" AND tblTaps.Archive=False" & _
" AND tblMain.Supervisor=""" & Me.cboloc & """"

What I want to know is if there can be a an "or" put in. for example

strWhere = "tblTaps.WorkPlan=""" & Me.Combo149 & _
""" AND tblTaps.Archive=False" & _
" AND tblMain.Supervisor=""" & Me.cboloc & """" & -
"or tblMain.UnitMan = """ & me.cboloc & """ & _
" or tblMain.AssistMan = """ & me.cboloc& """

Thanks for your help.
 
D

Douglas J. Steele

Sure you can do it. Just be aware of the order of precedence for boolean
operators. And gets evaluated before Or, so that likely won't do exactly
what you want.

I'm assuming you want the conditions on WorkPlan and Archive to always be
evaluated. The way you've currently got it, you'll get records where all
three of WorkPlan = Combo149, Archive = False and Supervisor = cboloc are
true plus all records where UnitMan = cboloc (regardless of the values of
WorkPlan and Archive) plus all records where AssistMan = cboloc (regardless
of the values of WorkPlan and Archive). I suspect you really want:

strWhere = "tblTaps.WorkPlan=""" & Me.Combo149 & _
""" AND tblTaps.Archive=False" & _
" AND (tblMain.Supervisor=""" & Me.cboloc & """" & -
"or tblMain.UnitMan = """ & me.cboloc & """ & _
" or tblMain.AssistMan = """ & me.cboloc& "")"
 
M

Marshall Barton

Afrosheen said:
I have a table with at least three fields that I need to create a filter for.
Here is the code:

strWhere = "tblTaps.WorkPlan=""" & Me.Combo149 & _
""" AND tblTaps.Archive=False" & _
" AND tblMain.Supervisor=""" & Me.cboloc & """"

What I want to know is if there can be a an "or" put in. for example

strWhere = "tblTaps.WorkPlan=""" & Me.Combo149 & _
""" AND tblTaps.Archive=False" & _
" AND tblMain.Supervisor=""" & Me.cboloc & """" & -
"or tblMain.UnitMan = """ & me.cboloc & """ & _
" or tblMain.AssistMan = """ & me.cboloc& """


Sure, just like you said, but be careful to get the spaces,
quotes and parenthesis correct.
 
A

Afrosheen via AccessMonster.com

Thanks fellas for getting back to me so fast. If truth be known, I was just
guessing at the coding. I guess I can chalk this one up for self confidence.

Marshall said:
I have a table with at least three fields that I need to create a filter for.
Here is the code:
[quoted text clipped - 10 lines]
"or tblMain.UnitMan = """ & me.cboloc & """ & _
" or tblMain.AssistMan = """ & me.cboloc& """

Sure, just like you said, but be careful to get the spaces,
quotes and parenthesis correct.
 
A

Afrosheen via AccessMonster.com

So much for the confidence. This is what I have and I keep getting an End of
Statement error on the last Parenthesis.

strWhere = "tblTaps.WorkPlan= """ & Me.Combo149 & _
""" AND tblTaps.Archive = False" & _
" AND (tblMain.Supervisor= """ & Me.cboloc & _
""" or tblMain.UnitMan= """ & Me.cboloc & _
""" or tblMain.AssistMan= """ & Me.cboloc & "")"


Thanks fellas for getting back to me so fast. If truth be known, I was just
guessing at the coding. I guess I can chalk this one up for self confidence.
[quoted text clipped - 4 lines]
Sure, just like you said, but be careful to get the spaces,
quotes and parenthesis correct.
 
T

Tony Toews [MVP]

Douglas J. Steele said:
Sure you can do it. Just be aware of the order of precedence for boolean
operators. And gets evaluated before Or, so that likely won't do exactly
what you want.

I never trust precedence order. I use lots of parentheses just to
ensure such selection criteria are doing what I want to do.

But then I also took a boolean algebra and programmable logic
controllers at the local college while in high school.

Tony
 
D

Douglas J. Steele

Yeah, sorry about that. My Insert key must have been pressed, so that the
parenthesis I put in replaced a double quote. You need three double quotes
before the closing parenthesis (and one after).

strWhere = "tblTaps.WorkPlan= """ & Me.Combo149 & _
""" AND tblTaps.Archive = False" & _
" AND (tblMain.Supervisor= """ & Me.cboloc & _
""" or tblMain.UnitMan= """ & Me.cboloc & _
""" or tblMain.AssistMan= """ & Me.cboloc & """)"

See what Allen Browne has at http://www.allenbrowne.com/casu-17.html for an
explanation of why.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Afrosheen via AccessMonster.com said:
So much for the confidence. This is what I have and I keep getting an End
of
Statement error on the last Parenthesis.

strWhere = "tblTaps.WorkPlan= """ & Me.Combo149 & _
""" AND tblTaps.Archive = False" & _
" AND (tblMain.Supervisor= """ & Me.cboloc & _
""" or tblMain.UnitMan= """ & Me.cboloc & _
""" or tblMain.AssistMan= """ & Me.cboloc & "")"


Thanks fellas for getting back to me so fast. If truth be known, I was
just
guessing at the coding. I guess I can chalk this one up for self
confidence.
I have a table with at least three fields that I need to create a filter
for.
Here is the code:
[quoted text clipped - 4 lines]
Sure, just like you said, but be careful to get the spaces,
quotes and parenthesis correct.
 
A

Afrosheen via AccessMonster.com

I really want to thank you and all the people who have made my life easier.
I've been working on this section of a module form for about 2 weeks and it's
finally coming together.

Thanks again
Yeah, sorry about that. My Insert key must have been pressed, so that the
parenthesis I put in replaced a double quote. You need three double quotes
before the closing parenthesis (and one after).

strWhere = "tblTaps.WorkPlan= """ & Me.Combo149 & _
""" AND tblTaps.Archive = False" & _
" AND (tblMain.Supervisor= """ & Me.cboloc & _
""" or tblMain.UnitMan= """ & Me.cboloc & _
""" or tblMain.AssistMan= """ & Me.cboloc & """)"

See what Allen Browne has at http://www.allenbrowne.com/casu-17.html for an
explanation of why.
So much for the confidence. This is what I have and I keep getting an End
of
[quoted text clipped - 17 lines]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top