filtering

A

Afrosheen

First of all thanks for looking at my question.

I have a filter that will not seem to work. Here it is.

dim stwhere3 as string

stwhere3 = "([shift]='A-Nights' or [shift]='B-Nights' or [shift]='Night
Shift') AND [status] = 'Working' or [status] = 'Training'"

filter = stwhere3
filter on = true

DoCmd.OpenReport stDocName, acPreview, , stwhere3, , "A-Nights Post Report"

What it is supposed to do is search the table where everyone on the [shift]
= the above but the [status] has to = "working" or "training"

A-Nights Post Report
Name Status Shift

TURMAN, TYRONE TRAINING DAY SHIFT
BISSETTE, LT. DWAYNE TRAINING A-NIGHTS
HARRISON, DERRICK WORKING A-NIGHTS
BUNN, WILLIAM TRAINING A-NIGHTS
BRASWELL, JOHN WORKING A-NIGHTS

This is what the report looks like. I'm just looking for those that work the
night shifts but I'm getting those on the day shift as well. This is where
the filter is NOT working.

Thanks.

I hope I've explained it ok.
 
D

Douglas J. Steele

Try putting parentheses around the second clause:

stwhere3 = "([shift]='A-Nights' or [shift]='B-Nights' or [shift]='Night
Shift') AND ([status] = 'Working' or [status] = 'Training')"

AND has a higher precedence of operation than OR. That means you're getting
records where the shift is one of the three mentioned AND the status is
working, as well as records where the status is training (regardless of
shift)
 
A

Afrosheen

Thanks Douglas. It worked out great. Thanks again for your help...



Douglas J. Steele said:
Try putting parentheses around the second clause:

stwhere3 = "([shift]='A-Nights' or [shift]='B-Nights' or [shift]='Night
Shift') AND ([status] = 'Working' or [status] = 'Training')"

AND has a higher precedence of operation than OR. That means you're getting
records where the shift is one of the three mentioned AND the status is
working, as well as records where the status is training (regardless of
shift)

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Afrosheen said:
First of all thanks for looking at my question.

I have a filter that will not seem to work. Here it is.

dim stwhere3 as string

stwhere3 = "([shift]='A-Nights' or [shift]='B-Nights' or [shift]='Night
Shift') AND [status] = 'Working' or [status] = 'Training'"

filter = stwhere3
filter on = true

DoCmd.OpenReport stDocName, acPreview, , stwhere3, , "A-Nights Post
Report"

What it is supposed to do is search the table where everyone on the
[shift]
= the above but the [status] has to = "working" or "training"

A-Nights Post Report
Name Status Shift

TURMAN, TYRONE TRAINING DAY SHIFT
BISSETTE, LT. DWAYNE TRAINING A-NIGHTS
HARRISON, DERRICK WORKING A-NIGHTS
BUNN, WILLIAM TRAINING A-NIGHTS
BRASWELL, JOHN WORKING A-NIGHTS

This is what the report looks like. I'm just looking for those that work
the
night shifts but I'm getting those on the day shift as well. This is where
the filter is NOT working.

Thanks.

I hope I've explained it ok.
 

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

Similar Threads

Programming Question 3
statements in a filter 1
Mutli Rosters within Division 2
Looking up a looked up look up value! 1
Best way 13
Real Data Formatting Challenge 3
statements in a filter 2
Insert Index into a Table 1

Top