B
BruceM
I have a database for keeping track of various statistics related to
manufacturing. The departments are either Plating or Painting. qryDept
contains the calculations, and is used as the recordsource for a form on
which the user can filter by month and department. I am using VBA code to
build a recordsource string according to choices in list boxes. I have used
debug.print to view the following recordsource code. [JobMonth] is obtained
by formatting the JobDate, which is a standard date field.
I can select for one or more months with no selections for department, or
one or more departments with no selection for month, or one department and
one month. In any of those cases the WHERE includes either AND or OR. When
I attempt to combine the two, I run into problems. I can't sort out what I
need to change. If I know the syntax I can probably figure out how to
assemble the string, but the trouble is that I can't get the syntax to do
what I need.
SELECT * FROM qryDept WHERE [JobMonth] = "02" OR [JobMonth] = "03" AND
[ProcDept] = "Painting"
Intended to show Painting jobs only for February and March, but shows
Plating and Painting
SELECT * FROM qryDept WHERE [JobMonth] = "02" AND [ProcDept] = "Plating" OR
[ProcDept] = "Painting"
Intended to show Plating or Painting for February only, but shows all months
The asterisk is for development purposes. Actual fields will be substituted
later.
manufacturing. The departments are either Plating or Painting. qryDept
contains the calculations, and is used as the recordsource for a form on
which the user can filter by month and department. I am using VBA code to
build a recordsource string according to choices in list boxes. I have used
debug.print to view the following recordsource code. [JobMonth] is obtained
by formatting the JobDate, which is a standard date field.
I can select for one or more months with no selections for department, or
one or more departments with no selection for month, or one department and
one month. In any of those cases the WHERE includes either AND or OR. When
I attempt to combine the two, I run into problems. I can't sort out what I
need to change. If I know the syntax I can probably figure out how to
assemble the string, but the trouble is that I can't get the syntax to do
what I need.
SELECT * FROM qryDept WHERE [JobMonth] = "02" OR [JobMonth] = "03" AND
[ProcDept] = "Painting"
Intended to show Painting jobs only for February and March, but shows
Plating and Painting
SELECT * FROM qryDept WHERE [JobMonth] = "02" AND [ProcDept] = "Plating" OR
[ProcDept] = "Painting"
Intended to show Plating or Painting for February only, but shows all months
The asterisk is for development purposes. Actual fields will be substituted
later.