Multiple Filters

G

Guest

I have 2 combo boxes on my form header that I want to use as filters. They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division (cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first one. How
can I get these to work together?
 
D

Douglas J. Steele

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True
 
G

Guest

Should that go under the After Update event for both combo boxes?

Douglas J. Steele said:
Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I have 2 combo boxes on my form header that I want to use as filters. They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division (cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first one. How
can I get these to work together?
 
G

Guest

I figured out where to put the code.
What if I now wanted to only have it filter the month and not the division?
I only want to use the division as an option not as a requirement. This way
users can select the month and have it show all the records and then only use
the divisions as an option. Basically they would just leave the division
combo box blank or I can add an "All" choice to the list.

Douglas J. Steele said:
Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I have 2 combo boxes on my form header that I want to use as filters. They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division (cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first one. How
can I get these to work together?
 
K

Ken Snell \(MVP\)

Try this (assumes that cboDivisions will be Null if no selection has been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



Secret Squirrel said:
I figured out where to put the code.
What if I now wanted to only have it filter the month and not the
division?
I only want to use the division as an option not as a requirement. This
way
users can select the month and have it show all the records and then only
use
the divisions as an option. Basically they would just leave the division
combo box blank or I can add an "All" choice to the list.

Douglas J. Steele said:
Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I have 2 combo boxes on my form header that I want to use as filters.
They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first one.
How
can I get these to work together?
 
G

Guest

Ken,
When I try that I'm getting a "Run-Time Error 3075", Syntax error (missing
operator) in query expression '([FPRODCL] = OR True) And [MONTHCOUNT] = 'May"

Here is the code I'm using.

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True
 
D

Douglas J. Steele

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while & doesn't.
If nothing's selected in cboDivisions (so that it's Null), the result of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null. However, Null &
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ken Snell (MVP) said:
Try this (assumes that cboDivisions will be Null if no selection has been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



Secret Squirrel said:
I figured out where to put the code.
What if I now wanted to only have it filter the month and not the
division?
I only want to use the division as an option not as a requirement. This
way
users can select the month and have it show all the records and then only
use
the divisions as an option. Basically they would just leave the division
combo box blank or I can add an "All" choice to the list.

Douglas J. Steele said:
Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I have 2 combo boxes on my form header that I want to use as filters.
They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first one.
How
can I get these to work together?
 
G

Guest

I tried that but the code stays red in the VB window. Doesn't seem to want to
accept the code as valid.

Douglas J. Steele said:
You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while & doesn't.
If nothing's selected in cboDivisions (so that it's Null), the result of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null. However, Null &
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ken Snell (MVP) said:
Try this (assumes that cboDivisions will be Null if no selection has been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



Secret Squirrel said:
I figured out where to put the code.
What if I now wanted to only have it filter the month and not the
division?
I only want to use the division as an option not as a requirement. This
way
users can select the month and have it show all the records and then only
use
the divisions as an option. Basically they would just leave the division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I have 2 combo boxes on my form header that I want to use as filters.
They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first one.
How
can I get these to work together?
 
D

Douglas J. Steele

Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I tried that but the code stays red in the VB window. Doesn't seem to want
to
accept the code as valid.

Douglas J. Steele said:
You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while &
doesn't.
If nothing's selected in cboDivisions (so that it's Null), the result of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null. However, Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Ken Snell (MVP) said:
Try this (assumes that cboDivisions will be Null if no selection has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



message I figured out where to put the code.
What if I now wanted to only have it filter the month and not the
division?
I only want to use the division as an option not as a requirement.
This
way
users can select the month and have it show all the records and then
only
use
the divisions as an option. Basically they would just leave the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I have 2 combo boxes on my form header that I want to use as
filters.
They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first
one.
How
can I get these to work together?
 
G

Guest

I'm now getting a compile error (expected expression). It's highlighting the
' after the [MONTHCOUNT] parameter.

Douglas J. Steele said:
Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I tried that but the code stays red in the VB window. Doesn't seem to want
to
accept the code as valid.

Douglas J. Steele said:
You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while &
doesn't.
If nothing's selected in cboDivisions (so that it's Null), the result of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null. However, Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Try this (assumes that cboDivisions will be Null if no selection has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



message I figured out where to put the code.
What if I now wanted to only have it filter the month and not the
division?
I only want to use the division as an option not as a requirement.
This
way
users can select the month and have it show all the records and then
only
use
the divisions as an option. Basically they would just leave the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I have 2 combo boxes on my form header that I want to use as
filters.
They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first
one.
How
can I get these to work together?
 
D

Douglas J. Steele

Damn. Another typo on my part. Left off an opening quote:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Sorry about that!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I'm now getting a compile error (expected expression). It's highlighting
the
' after the [MONTHCOUNT] parameter.

Douglas J. Steele said:
Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I tried that but the code stays red in the VB window. Doesn't seem to
want
to
accept the code as valid.

:

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while &
doesn't.
If nothing's selected in cboDivisions (so that it's Null), the result
of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null. However,
Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Try this (assumes that cboDivisions will be Null if no selection has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



in
message I figured out where to put the code.
What if I now wanted to only have it filter the month and not the
division?
I only want to use the division as an option not as a requirement.
This
way
users can select the month and have it show all the records and
then
only
use
the divisions as an option. Basically they would just leave the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


in
message I have 2 combo boxes on my form header that I want to use as
filters.
They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first
one.
How
can I get these to work together?
 
G

Guest

It's working perfectly now! Thank you for all your help Doug! Appreciate it!

Douglas J. Steele said:
Damn. Another typo on my part. Left off an opening quote:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Sorry about that!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I'm now getting a compile error (expected expression). It's highlighting
the
' after the [MONTHCOUNT] parameter.

Douglas J. Steele said:
Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I tried that but the code stays red in the VB window. Doesn't seem to
want
to
accept the code as valid.

:

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while &
doesn't.
If nothing's selected in cboDivisions (so that it's Null), the result
of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null. However,
Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Try this (assumes that cboDivisions will be Null if no selection has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



in
message I figured out where to put the code.
What if I now wanted to only have it filter the month and not the
division?
I only want to use the division as an option not as a requirement.
This
way
users can select the month and have it show all the records and
then
only
use
the divisions as an option. Basically they would just leave the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


in
message I have 2 combo boxes on my form header that I want to use as
filters.
They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first
one.
How
can I get these to work together?
 
G

Guest

Actually I stand corrected. When I open the form and there is no value in
either combo box and then I select a month from the cboMonthSelect box it
errors out. The only way it will work when I first open the form is to make a
selection in the cboDivisions box and then choose a month it works fine. But
then I have to go back and clear the value from the cboDivisions box to have
it list all divisions for that month.

Douglas J. Steele said:
Damn. Another typo on my part. Left off an opening quote:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Sorry about that!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I'm now getting a compile error (expected expression). It's highlighting
the
' after the [MONTHCOUNT] parameter.

Douglas J. Steele said:
Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I tried that but the code stays red in the VB window. Doesn't seem to
want
to
accept the code as valid.

:

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while &
doesn't.
If nothing's selected in cboDivisions (so that it's Null), the result
of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null. However,
Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Try this (assumes that cboDivisions will be Null if no selection has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



in
message I figured out where to put the code.
What if I now wanted to only have it filter the month and not the
division?
I only want to use the division as an option not as a requirement.
This
way
users can select the month and have it show all the records and
then
only
use
the divisions as an option. Basically they would just leave the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


in
message I have 2 combo boxes on my form header that I want to use as
filters.
They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first
one.
How
can I get these to work together?
 
D

Douglas J. Steele

Okay, let's step back and not be so fancy for a moment.

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
Dim strFilter As String

If IsNull(Me!cboDivisions) = False Then
strFilter = "[FPRODCL] = " & Me!cboDivisions & " AND "
End If

strFilter = strFilter & "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Me.Filter = strFilter
Me.FilterOn = True

End Sub

If that still fails, put a break point inside the routine and single-step
through it, checking to see which lines are executing.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
Actually I stand corrected. When I open the form and there is no value in
either combo box and then I select a month from the cboMonthSelect box it
errors out. The only way it will work when I first open the form is to
make a
selection in the cboDivisions box and then choose a month it works fine.
But
then I have to go back and clear the value from the cboDivisions box to
have
it list all divisions for that month.

Douglas J. Steele said:
Damn. Another typo on my part. Left off an opening quote:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Sorry about that!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
I'm now getting a compile error (expected expression). It's
highlighting
the
' after the [MONTHCOUNT] parameter.

:

Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I tried that but the code stays red in the VB window. Doesn't seem to
want
to
accept the code as valid.

:

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while &
doesn't.
If nothing's selected in cboDivisions (so that it's Null), the
result
of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null.
However,
Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to
populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message
Try this (assumes that cboDivisions will be Null if no selection
has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



"Secret Squirrel" <[email protected]>
wrote
in
message
I figured out where to put the code.
What if I now wanted to only have it filter the month and not
the
division?
I only want to use the division as an option not as a
requirement.
This
way
users can select the month and have it show all the records and
then
only
use
the divisions as an option. Basically they would just leave the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Secret Squirrel" <[email protected]>
wrote
in
message
I have 2 combo boxes on my form header that I want to use as
filters.
They
both work but not together. I want to be able to filter by
month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] &
"'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the
first
one.
How
can I get these to work together?
 
K

Ken Snell \(MVP\)

Yep, that makes sense as an error. It's trying to put a Null value into the
concatenation. (My fault -- I was rushing to finish the post before running
out the door, and was trying to "make it similar to" what you'd do in the
query designer window.)

I'd go with the last solution posted by Douglas Steele.

--

Ken Snell
<MS ACCESS MVP>


Secret Squirrel said:
Ken,
When I try that I'm getting a "Run-Time Error 3075", Syntax error (missing
operator) in query expression '([FPRODCL] = OR True) And [MONTHCOUNT] =
'May"

Here is the code I'm using.

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True


Secret Squirrel said:
I have 2 combo boxes on my form header that I want to use as filters.
They
both work but not together. I want to be able to filter by month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] & "'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the first one. How
can I get these to work together?
 
G

Guest

Ok I ran the code and when I first opened the form and tried to select a
month it gave me an error and pointed to this part of the code:

Me.Filter = strFilter

It didn't even filter to the month I selected. It just gave me an error.

Douglas J. Steele said:
Okay, let's step back and not be so fancy for a moment.

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
Dim strFilter As String

If IsNull(Me!cboDivisions) = False Then
strFilter = "[FPRODCL] = " & Me!cboDivisions & " AND "
End If

strFilter = strFilter & "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Me.Filter = strFilter
Me.FilterOn = True

End Sub

If that still fails, put a break point inside the routine and single-step
through it, checking to see which lines are executing.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
Actually I stand corrected. When I open the form and there is no value in
either combo box and then I select a month from the cboMonthSelect box it
errors out. The only way it will work when I first open the form is to
make a
selection in the cboDivisions box and then choose a month it works fine.
But
then I have to go back and clear the value from the cboDivisions box to
have
it list all divisions for that month.

Douglas J. Steele said:
Damn. Another typo on my part. Left off an opening quote:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Sorry about that!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I'm now getting a compile error (expected expression). It's
highlighting
the
' after the [MONTHCOUNT] parameter.

:

Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I tried that but the code stays red in the VB window. Doesn't seem to
want
to
accept the code as valid.

:

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while &
doesn't.
If nothing's selected in cboDivisions (so that it's Null), the
result
of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null.
However,
Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to
populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message
Try this (assumes that cboDivisions will be Null if no selection
has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



"Secret Squirrel" <[email protected]>
wrote
in
message
I figured out where to put the code.
What if I now wanted to only have it filter the month and not
the
division?
I only want to use the division as an option not as a
requirement.
This
way
users can select the month and have it show all the records and
then
only
use
the divisions as an option. Basically they would just leave the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Secret Squirrel" <[email protected]>
wrote
in
message
I have 2 combo boxes on my form header that I want to use as
filters.
They
both work but not together. I want to be able to filter by
month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect] &
"'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the
first
one.
How
can I get these to work together?
 
D

Douglas J. Steele

And what's in strFilter when this happens?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
Ok I ran the code and when I first opened the form and tried to select a
month it gave me an error and pointed to this part of the code:

Me.Filter = strFilter

It didn't even filter to the month I selected. It just gave me an error.

Douglas J. Steele said:
Okay, let's step back and not be so fancy for a moment.

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
Dim strFilter As String

If IsNull(Me!cboDivisions) = False Then
strFilter = "[FPRODCL] = " & Me!cboDivisions & " AND "
End If

strFilter = strFilter & "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Me.Filter = strFilter
Me.FilterOn = True

End Sub

If that still fails, put a break point inside the routine and single-step
through it, checking to see which lines are executing.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
Actually I stand corrected. When I open the form and there is no value
in
either combo box and then I select a month from the cboMonthSelect box
it
errors out. The only way it will work when I first open the form is to
make a
selection in the cboDivisions box and then choose a month it works
fine.
But
then I have to go back and clear the value from the cboDivisions box to
have
it list all divisions for that month.

:

Damn. Another typo on my part. Left off an opening quote:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Sorry about that!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I'm now getting a compile error (expected expression). It's
highlighting
the
' after the [MONTHCOUNT] parameter.

:

Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


in
message I tried that but the code stays red in the VB window. Doesn't seem
to
want
to
accept the code as valid.

:

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while
&
doesn't.
If nothing's selected in cboDivisions (so that it's Null), the
result
of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null.
However,
Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to
populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message
Try this (assumes that cboDivisions will be Null if no
selection
has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



"Secret Squirrel" <[email protected]>
wrote
in
message
I figured out where to put the code.
What if I now wanted to only have it filter the month and not
the
division?
I only want to use the division as an option not as a
requirement.
This
way
users can select the month and have it show all the records
and
then
only
use
the divisions as an option. Basically they would just leave
the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Secret Squirrel" <[email protected]>
wrote
in
message
I have 2 combo boxes on my form header that I want to use
as
filters.
They
both work but not together. I want to be able to filter by
month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect]
&
"'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect &
"'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the
first
one.
How
can I get these to work together?
 
G

Guest

Nothing. It just errors out before I even select anything.

Douglas J. Steele said:
And what's in strFilter when this happens?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
Ok I ran the code and when I first opened the form and tried to select a
month it gave me an error and pointed to this part of the code:

Me.Filter = strFilter

It didn't even filter to the month I selected. It just gave me an error.

Douglas J. Steele said:
Okay, let's step back and not be so fancy for a moment.

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
Dim strFilter As String

If IsNull(Me!cboDivisions) = False Then
strFilter = "[FPRODCL] = " & Me!cboDivisions & " AND "
End If

strFilter = strFilter & "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Me.Filter = strFilter
Me.FilterOn = True

End Sub

If that still fails, put a break point inside the routine and single-step
through it, checking to see which lines are executing.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message Actually I stand corrected. When I open the form and there is no value
in
either combo box and then I select a month from the cboMonthSelect box
it
errors out. The only way it will work when I first open the form is to
make a
selection in the cboDivisions box and then choose a month it works
fine.
But
then I have to go back and clear the value from the cboDivisions box to
have
it list all divisions for that month.

:

Damn. Another typo on my part. Left off an opening quote:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Sorry about that!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message I'm now getting a compile error (expected expression). It's
highlighting
the
' after the [MONTHCOUNT] parameter.

:

Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


in
message I tried that but the code stays red in the VB window. Doesn't seem
to
want
to
accept the code as valid.

:

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls, while
&
doesn't.
If nothing's selected in cboDivisions (so that it's Null), the
result
of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null.
However,
Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to
populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message
Try this (assumes that cboDivisions will be Null if no
selection
has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



"Secret Squirrel" <[email protected]>
wrote
in
message
I figured out where to put the code.
What if I now wanted to only have it filter the month and not
the
division?
I only want to use the division as an option not as a
requirement.
This
way
users can select the month and have it show all the records
and
then
only
use
the divisions as an option. Basically they would just leave
the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Secret Squirrel" <[email protected]>
wrote
in
message
I have 2 combo boxes on my form header that I want to use
as
filters.
They
both work but not together. I want to be able to filter by
month
(cboMonthSelect) and then filter those results by division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" & Me![cboMonthSelect]
&
"'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect &
"'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out the
first
one.
How
can I get these to work together?
 
D

Douglas J. Steele

You said that it fails on the line of code

Me.Filter = strFilter

I was asking what value was in strFilter when it fails.

Try putting

Debug.Print strFilter

before the line that's failing, and then looking in the Immediate Window
(Ctrl-G) to see what's printed.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
Nothing. It just errors out before I even select anything.

Douglas J. Steele said:
And what's in strFilter when this happens?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


Secret Squirrel said:
Ok I ran the code and when I first opened the form and tried to select
a
month it gave me an error and pointed to this part of the code:

Me.Filter = strFilter

It didn't even filter to the month I selected. It just gave me an
error.

:

Okay, let's step back and not be so fancy for a moment.

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
Dim strFilter As String

If IsNull(Me!cboDivisions) = False Then
strFilter = "[FPRODCL] = " & Me!cboDivisions & " AND "
End If

strFilter = strFilter & "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Me.Filter = strFilter
Me.FilterOn = True

End Sub

If that still fails, put a break point inside the routine and
single-step
through it, checking to see which lines are executing.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message Actually I stand corrected. When I open the form and there is no
value
in
either combo box and then I select a month from the cboMonthSelect
box
it
errors out. The only way it will work when I first open the form is
to
make a
selection in the cboDivisions box and then choose a month it works
fine.
But
then I have to go back and clear the value from the cboDivisions box
to
have
it list all divisions for that month.

:

Damn. Another typo on my part. Left off an opening quote:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Sorry about that!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


in
message I'm now getting a compile error (expected expression). It's
highlighting
the
' after the [MONTHCOUNT] parameter.

:

Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Secret Squirrel" <[email protected]>
wrote
in
message
I tried that but the code stays red in the VB window. Doesn't
seem
to
want
to
accept the code as valid.

:

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls,
while
&
doesn't.
If nothing's selected in cboDivisions (so that it's Null),
the
result
of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null.
However,
Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to
populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message
Try this (assumes that cboDivisions will be Null if no
selection
has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



"Secret Squirrel"
<[email protected]>
wrote
in
message
I figured out where to put the code.
What if I now wanted to only have it filter the month and
not
the
division?
I only want to use the division as an option not as a
requirement.
This
way
users can select the month and have it show all the
records
and
then
only
use
the divisions as an option. Basically they would just
leave
the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Secret Squirrel"
<[email protected]>
wrote
in
message
I have 2 combo boxes on my form header that I want to
use
as
filters.
They
both work but not together. I want to be able to filter
by
month
(cboMonthSelect) and then filter those results by
division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" &
Me![cboMonthSelect]
&
"'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect &
"'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out
the
first
one.
How
can I get these to work together?
 
G

Guest

Not sure what I did wrong but for some reason it's working now. No need to
debug it now. Thanks for your help Doug. Appreciate it.

Douglas J. Steele said:
You said that it fails on the line of code

Me.Filter = strFilter

I was asking what value was in strFilter when it fails.

Try putting

Debug.Print strFilter

before the line that's failing, and then looking in the Immediate Window
(Ctrl-G) to see what's printed.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Secret Squirrel said:
Nothing. It just errors out before I even select anything.

Douglas J. Steele said:
And what's in strFilter when this happens?

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message Ok I ran the code and when I first opened the form and tried to select
a
month it gave me an error and pointed to this part of the code:

Me.Filter = strFilter

It didn't even filter to the month I selected. It just gave me an
error.

:

Okay, let's step back and not be so fancy for a moment.

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
Dim strFilter As String

If IsNull(Me!cboDivisions) = False Then
strFilter = "[FPRODCL] = " & Me!cboDivisions & " AND "
End If

strFilter = strFilter & "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Me.Filter = strFilter
Me.FilterOn = True

End Sub

If that still fails, put a break point inside the routine and
single-step
through it, checking to see which lines are executing.

--
Doug Steele, Microsoft Access MVP

(no private e-mails, please)


message Actually I stand corrected. When I open the form and there is no
value
in
either combo box and then I select a month from the cboMonthSelect
box
it
errors out. The only way it will work when I first open the form is
to
make a
selection in the cboDivisions box and then choose a month it works
fine.
But
then I have to go back and clear the value from the cboDivisions box
to
have
it list all divisions for that month.

:

Damn. Another typo on my part. Left off an opening quote:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& "[MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

Sorry about that!

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


in
message I'm now getting a compile error (expected expression). It's
highlighting
the
' after the [MONTHCOUNT] parameter.

:

Sorry, typo on my part. One too many open parentheses:

Me.Filter = ("[FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Secret Squirrel" <[email protected]>
wrote
in
message
I tried that but the code stays red in the VB window. Doesn't
seem
to
want
to
accept the code as valid.

:

You could also try:

Me.Filter = ("([FPRODCL] = " + Me!cboDivisions + " AND ") _
& [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"

This takes advantage of the fact that + propagates Nulls,
while
&
doesn't.
If nothing's selected in cboDivisions (so that it's Null),
the
result
of
("([FPRODCL] = " + Me!cboDivisions + " AND ") will be Null.
However,
Null
&
[MONTHCOUNT] = '" & Me!cboMonthSelect & "'" will continue to
populate.

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


message
Try this (assumes that cboDivisions will be Null if no
selection
has
been
made):

Me.Filter = "([FPRODCL] = " & Me!cboDivisions & _
" OR " & IsNull(Me!cboDivisions) & ")" & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"


--

Ken Snell
<MS ACCESS MVP>



"Secret Squirrel"
<[email protected]>
wrote
in
message
I figured out where to put the code.
What if I now wanted to only have it filter the month and
not
the
division?
I only want to use the division as an option not as a
requirement.
This
way
users can select the month and have it show all the
records
and
then
only
use
the divisions as an option. Basically they would just
leave
the
division
combo box blank or I can add an "All" choice to the list.

:

Me.Filter = "[FPRODCL] = " & Me!cboDivisions & _
" AND [MONTHCOUNT] = '" & Me!cboMonthSelect & "'"
Me.FilterOn = True



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


"Secret Squirrel"
<[email protected]>
wrote
in
message
I have 2 combo boxes on my form header that I want to
use
as
filters.
They
both work but not together. I want to be able to filter
by
month
(cboMonthSelect) and then filter those results by
division
(cboDivisions).
Right now this how I have it set up:

Private Sub cboDivisions_AfterUpdate()
Me.Filter = "[FPRODCL] = " & Me!cboDivisions
Me.FilterOn = True
End Sub

Private Sub cboMonthSelect_AfterUpdate()
' Find the record that matches the control.
'Dim rs As Object

'Set rs = Me.Recordset.Clone
'rs.FindFirst "[MONTHCOUNT] = '" &
Me![cboMonthSelect]
&
"'"
'If Not rs.EOF Then Me.Bookmark = rs.Bookmark
Me.Filter = "[MONTHCOUNT] = '" & Me!cboMonthSelect &
"'"
Me.FilterOn = True

End Sub

When I filter by one and then the other it cancels out
the
first
one.
How
can I get these to work together?
 

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