filtering

  • Thread starter Thread starter Afrosheen
  • Start date Start date
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.
 
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)
 
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.
 
Back
Top