Multiple Filters on Continuous Form

P

poalman

Hi,

I have a continuous form that is based off of a table, each record has
12 fields, 10 of which I wish the user to be able to filter on.

The form has 10 combo boxes in the form header which are unbound and
have Row Sources like this;

SELECT DISTINCT tblAuditActions.auditor
FROM tblAuditActions
WHERE len(tblAuditActions.auditor)>0
UNION Select "(All)" as Bogus From tblAuditActions
UNION Select "(Blank)" as Bogus2 From tblAuditActions
ORDER BY [auditor];

tblAuditActions is the table the form is base on by the way.

What I'm aiming for is something similar to excels auto filter, where
when the form opens all the drops downs are set to "(All)" and every
record is shown, and when a user selects a value to filter the form re-
queries and the other drop downs re-query to only show values that
appear on the filtered list of records.

I've got to the point where I can filter the form but only 1 field at
a time, but I can't get the "(Blank)" selection from my union query to
only bring up fields with a blank entry.

Any advice or pointers you can offer will be hugely appreciated!

Thanks!!
 
D

Douglas J. Steele

The SQL for your condition should be something like:

WHERE auditor = Forms!NameOfForm!NameOfComboBox
OR Forms!NameOfForm!NameOfComboBox = "(All)"
OR (Forms!NameOfForm!NameOfComboBox = "(Blank)"
AND auditor = Null)
 
P

poalman

The SQL for your condition should be something like:

WHERE auditor = Forms!NameOfForm!NameOfComboBox
OR Forms!NameOfForm!NameOfComboBox = "(All)"
OR (Forms!NameOfForm!NameOfComboBox = "(Blank)"
AND auditor = Null)

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no private e-mails, please)




I have a continuous form that is based off of a table, each record has
12 fields, 10 of which I wish the user to be able to filter on.
The form has 10 combo boxes in the form header which are unbound and
have Row Sources like this;
SELECT DISTINCT tblAuditActions.auditor
FROM tblAuditActions
WHERE len(tblAuditActions.auditor)>0
UNION Select "(All)" as Bogus From tblAuditActions
UNION Select "(Blank)" as Bogus2 From tblAuditActions
ORDER BY [auditor];
tblAuditActions is the table the form is base on by the way.
What I'm aiming for is something similar to excels auto filter, where
when the form opens all the drops downs are set to "(All)" and every
record is shown, and when a user selects a value to filter the form re-
queries and the other drop downs re-query to only show values that
appear on the filtered list of records.
I've got to the point where I can filter the form but only 1 field at
a time, but I can't get the "(Blank)" selection from my union query to
only bring up fields with a blank entry.
Any advice or pointers you can offer will be hugely appreciated!
Thanks!!- Hide quoted text -

- Show quoted text -

Thanks Doug,
That shunted me in the right direction and I've got the filter working
this morning :)

However, the filter works on the fields that are text data types, but
I can't for the life of me get it to work on the fields that are
date. I have tried all sorts of syntax in vb in a trial and error
type approach but not getting any closer to solving this one.

I think at first it wasn't working because the union was adding text
value (All) and (Blank) into a date field so I added a hidden column
in the combo box that I set as the bound column which unioned the all
to a random date (01/01/1900) and for blank i used (02/01/1900) so
then atleast i can seperate then in VB with an IF.

I know the solution I have is more than likely extremely long winded
and probably could be achieved with a lot less effort but I just need
to get something out that works and the workings behind it are far
less important.

I'll post below what I have so far in case it helps you understand
where I'm at.

Function FilterString(cboDate As Date, cboRef As String, cboType As
String, cboAuditor As String, cboProcessStep As String, cboProject As
String, cboSubProject As String, cboActionee As String, cboStatus As
String, cboReviewDate As Date, cboForecastDate As Date,
cboCompletionCloseDate As Date)

Dim strCboDate As String
Dim strCboRef As String
Dim strCboType As String
Dim strCboAuditor As String
Dim strCboProcessStep As String
Dim strCboProject As String
Dim strCboSubProject As String
Dim strCboActionee As String
Dim strCboStatus As String
Dim strCboReviewDate As String
Dim strCboForecastDate As String
Dim strCboCompletionCloseDate As String
Dim StrFilter As String


If cboDate = #1/1/1900# Then
strCboDate = "'' AND"
Else
strCboDate = "[Date] = #" & cboDate & "# AND"
End If


If cboRef = "(All)" Then
strCboRef = " '' AND"
Else
strCboRef = " Ref = '" & cboRef & "' AND"
End If

If cboType = "(Blank)" Then
strCboType = " Type Is Null AND"
Else
If cboType = "(All)" Then
strCboType = " '' AND"
Else
strCboType = " Type = '" & cboType & "' AND"
End If
End If

If cboAuditor = "(Blank)" Then
strCboAuditor = " Auditor Is Null AND"
Else
If cboAuditor = "(All)" Then
strCboAuditor = " '' AND"
Else
strCboAuditor = " Auditor = '" & cboAuditor & "' AND"
End If
End If

If cboProcessStep = "(Blank)" Then
strCboProcessStep = " [Process Step] Is Null AND"
Else
If cboProcessStep = "(All)" Then
strCboProcessStep = " '' AND"
Else
strCboProcessStep = " [Process Step] = '" & cboProcessStep &
"' AND"
End If
End If

If cboProject = "(All)" Then
strCboProject = " '' AND"
Else
strCboProject = " Project = '" & cboProject & "' AND"
End If

If cboSubProject = "(All)" Then
strCboSubProject = " '' AND"
Else
strCboSubProject = " [Sub Project] = '" & cboSubProject & "' AND"
End If

If cboActionee = "(Blank)" Then
strCboActionee = " Actionee Is Null AND"
Else
If cboActionee = "(All)" Then
strCboActionee = " '' AND"
Else
strCboActionee = " Actionee = '" & cboActionee & "' AND"
End If
End If

If cboStatus = "(Blank)" Then
strCboStatus = " Status Is Null AND"
Else
If cboStatus = "(All)" Then
strCboStatus = " '' AND"
Else
strCboStatus = " Status = '" & cboStatus & "' AND"
End If
End If

If cboReviewDate = #1/1/1900# Then
strCboReviewDate = " [Review Date] Is Null AND"
Else
If cboReviewDate = #2/1/1900# Then
strCboReviewDate = " '' AND"
Else
strCboReviewDate = " [Review Date] = '" & cboReviewDate & "'
AND"
End If
End If

If cboForecastDate = #1/1/1900# Then
strCboForecastDate = " [Forecast Date] Is Null AND"
Else
If cboForecastDate = #2/1/1900# Then
strCboForecastDate = " '' AND"
Else
strCboForecastDate = " [Forecast Date] = '" & cboForecastDate
& "' AND"
End If
End If

If cboCompletionCloseDate = #1/1/1900# Then
strCboCompletionCloseDate = " [Completion/Close Date] Is Null"
Else
If cboCompletionCloseDate = #2/1/1900# Then
strCboCompletionCloseDate = " ''"
Else
strCboCompletionCloseDate = " [Completion/Close Date] = #" &
cboCompletionCloseDate & "#"
End If
End If

StrFilter = strCboDate & strCboRef & strCboType & strCboAuditor &
strCboProcessStep & strCboProject & strCboSubProject & strCboActionee
& strCboStatus & strCboReviewDate & strCboForecastDate &
strCboCompletionCloseDate

FilterString = StrFilter

End Function



example of combo after update event (all the other combos are the
same):

Private Sub cboCompletionCloseDate_AfterUpdate()

strToFilter = FilterString(Me.cboDate, Me.cboRef, Me.cboType,
Me.cboAuditor, Me.cboProcessStep, Me.cboProject, Me.cboSubProject,
Me.cboActionee, Me.cboStatus, Me.cboReviewDate, Me.cboForecastDate,
Me.cboCompletionCloseDate)
Me.Filter = strToFilter
Me.FilterOn = True

If Me.cboCompletionCloseDate.Value <> #1/1/1900# Then
Me.cboCompletionCloseDate.BorderWidth = 2
Me.cboCompletionCloseDate.BorderColor = 16711680
Else
Me.cboCompletionCloseDate.BorderColor = 0
Me.cboCompletionCloseDate.BorderWidth = 0
End If
End Sub


and an example of the row source of the combo:

SELECT DISTINCT format(tblAuditActions.[completion/close date],"yyyy/
mm/dd") as ccd2 ,tblAuditActions.[completion/close
date],tblAuditActions.[completion/close date]
FROM tblAuditActions
WHERE len(tblAuditActions.[completion/close date])>0
UNION Select "(Blank)" as Bogus, "(Blank)" as Bogus2, "01/01/1900" as
bogus3
From tblAuditActions
UNION Select "(All)" as Bogus, "(All)" as Bogus2, "02/01/1900" as
bogus3
From tblAuditActions
ORDER BY ccd2;

column count: 3
column widths: 0cm;2.547cm;0cm
bound column: 3


Sorry about the lengthy post, and thanks for any further pointers you
can provide!!
 
D

Douglas J. Steele

See whether changing your row source to the following helps:

SELECT DISTINCT format(tblAuditActions.[completion/close date],"yyyy/
mm/dd") as ccd2 ,tblAuditActions.[completion/close
date],tblAuditActions.[completion/close date]
FROM tblAuditActions
WHERE len(tblAuditActions.[completion/close date])>0
UNION Select "(Blank)", "(Blank)", #01/01/1900#
From tblAuditActions
UNION Select "(All)", "(All)", #02/01/1900#
From tblAuditActions
ORDER BY ccd2;

Note that there's really no need for the As Bogus, As Bogus2 etc. in your
Select statement.
 
P

poalman

See whether changing your row source to the following helps:

SELECT DISTINCT format(tblAuditActions.[completion/close date],"yyyy/
mm/dd") as ccd2 ,tblAuditActions.[completion/close
date],tblAuditActions.[completion/close date]
FROM tblAuditActions
WHERE len(tblAuditActions.[completion/close date])>0
UNION Select "(Blank)", "(Blank)", #01/01/1900#
From tblAuditActions
UNION Select "(All)", "(All)", #02/01/1900#
From tblAuditActions
ORDER BY ccd2;

Note that there's really no need for the As Bogus, As Bogus2 etc. in your
Select statement.

--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)






Thanks Doug,
That shunted me in the right direction and I've got the filter working
this morning :)
However, the filter works on the fields that are text data types, but
I can't for the life of me get it to work on the fields that are
date.  I have tried all sorts of syntax in vb in a trial and error
type approach but not getting any closer to solving this one.
I think at first it wasn't working because the union was adding text
value (All) and (Blank) into a date field so I added a hidden column
in the combo box that I set as the bound column which unioned the all
to a random date (01/01/1900) and for blank i used (02/01/1900) so
then atleast i can seperate then in VB with an IF.
and an example of the row source of the combo:
SELECT DISTINCT format(tblAuditActions.[completion/close date],"yyyy/
mm/dd") as ccd2 ,tblAuditActions.[completion/close
date],tblAuditActions.[completion/close date]
FROM tblAuditActions
WHERE len(tblAuditActions.[completion/close date])>0
UNION Select "(Blank)" as Bogus, "(Blank)" as Bogus2, "01/01/1900" as
bogus3
From tblAuditActions
UNION Select "(All)" as Bogus, "(All)" as Bogus2, "02/01/1900" as
bogus3
From tblAuditActions
ORDER BY ccd2;
column count: 3
column widths: 0cm;2.547cm;0cm
bound column: 3
Sorry about the lengthy post, and thanks for any further pointers you
can provide!!- Hide quoted text -

- Show quoted text -

Hi again Doug, thanks for your reply!

I have made the suggested changes but I am getting type mis match
error on the after update.

One very odd thing I've noticed though was that on one of my fields
when adding in the 3rd column to the combo box i forgot to set the
column count field to 3 and accidently left it as 2 where the bound
column is 3. and for that field the filter works on the all and blank
selections, but I get a "Run-time error '2001'; You cancelled the
previous operation." when I select anything else. maybe because the
dates in the combo box arn't truely date values?? but I'm only
guessing :)

Poal.
 
P

poalman

See whether changing your row source to the following helps:
SELECT DISTINCT format(tblAuditActions.[completion/close date],"yyyy/
mm/dd") as ccd2 ,tblAuditActions.[completion/close
date],tblAuditActions.[completion/close date]
FROM tblAuditActions
WHERE len(tblAuditActions.[completion/close date])>0
UNION Select "(Blank)", "(Blank)", #01/01/1900#
From tblAuditActions
UNION Select "(All)", "(All)", #02/01/1900#
From tblAuditActions
ORDER BY ccd2;
Note that there's really no need for the As Bogus, As Bogus2 etc. in your
Select statement.
news:dd251222-4094-48dd-9841-574f06931ab5@m45g2000hsb.googlegroups.com...
Thanks Doug,
That shunted me in the right direction and I've got the filter working
this morning :)
However, the filter works on the fields that are text data types, but
I can't for the life of me get it to work on the fields that are
date.  I have tried all sorts of syntax in vb in a trial and error
type approach but not getting any closer to solving this one.
I think at first it wasn't working because the union was adding text
value (All) and (Blank) into a date field so I added a hidden column
in the combo box that I set as the bound column which unioned the all
to a random date (01/01/1900) and for blank i used (02/01/1900) so
then atleast i can seperate then in VB with an IF.
and an example of the row source of the combo:
SELECT DISTINCT format(tblAuditActions.[completion/close date],"yyyy/
mm/dd") as ccd2 ,tblAuditActions.[completion/close
date],tblAuditActions.[completion/close date]
FROM tblAuditActions
WHERE len(tblAuditActions.[completion/close date])>0
UNION Select "(Blank)" as Bogus, "(Blank)" as Bogus2, "01/01/1900" as
bogus3
From tblAuditActions
UNION Select "(All)" as Bogus, "(All)" as Bogus2, "02/01/1900" as
bogus3
From tblAuditActions
ORDER BY ccd2;
column count: 3
column widths: 0cm;2.547cm;0cm
bound column: 3
Sorry about the lengthy post, and thanks for any further pointers you
can provide!!- Hide quoted text -
- Show quoted text -

Hi again Doug, thanks for your reply!

I have made the suggested changes but I am getting type mis match
error on the after update.

One very odd thing I've noticed though was that on one of my fields
when adding in the 3rd column to the combo box i forgot to set the
column count field to 3 and accidently left it as 2 where the bound
column is 3. and for that field the filter works on the all and blank
selections, but I get a "Run-time error '2001'; You cancelled the
previous operation." when I select anything else.  maybe because the
dates in the combo box arn't truely date values?? but I'm only
guessing :)

Poal.- Hide quoted text -

- Show quoted text -

I've also noticed that in debug mode the values getting passed into
the function are in american format(mm/dd/yyyy). I have no idea if
this will affect whats going on or not. I'll just carry on playing
with it and see where I get :)
 
P

poalman

See whether changing your row source to the following helps:
SELECT DISTINCT format(tblAuditActions.[completion/close date],"yyyy/
mm/dd") as ccd2 ,tblAuditActions.[completion/close
date],tblAuditActions.[completion/close date]
FROM tblAuditActions
WHERE len(tblAuditActions.[completion/close date])>0
UNION Select "(Blank)", "(Blank)", #01/01/1900#
From tblAuditActions
UNION Select "(All)", "(All)", #02/01/1900#
From tblAuditActions
ORDER BY ccd2;
Note that there's really no need for the As Bogus, As Bogus2 etc. in your
Select statement.
--
Doug Steele, Microsoft Access MVPhttp://I.Am/DougSteele
(no e-mails, please!)

Thanks Doug,
That shunted me in the right direction and I've got the filter working
this morning :)
However, the filter works on the fields that are text data types, but
I can't for the life of me get it to work on the fields that are
date.  I have tried all sorts of syntax in vb in a trial and error
type approach but not getting any closer to solving this one.
I think at first it wasn't working because the union was adding text
value (All) and (Blank) into a date field so I added a hidden column
in the combo box that I set as the bound column which unioned the all
to a random date (01/01/1900) and for blank i used (02/01/1900) so
then atleast i can seperate then in VB with an IF.
and an example of the row source of the combo:
SELECT DISTINCT format(tblAuditActions.[completion/close date],"yyyy/
mm/dd") as ccd2 ,tblAuditActions.[completion/close
date],tblAuditActions.[completion/close date]
FROM tblAuditActions
WHERE len(tblAuditActions.[completion/close date])>0
UNION Select "(Blank)" as Bogus, "(Blank)" as Bogus2, "01/01/1900" as
bogus3
From tblAuditActions
UNION Select "(All)" as Bogus, "(All)" as Bogus2, "02/01/1900" as
bogus3
From tblAuditActions
ORDER BY ccd2;
column count: 3
column widths: 0cm;2.547cm;0cm
bound column: 3
Sorry about the lengthy post, and thanks for any further pointers you
can provide!!- Hide quoted text -
- Show quoted text -
Hi again Doug, thanks for your reply!
I have made the suggested changes but I am getting type mis match
error on the after update.
One very odd thing I've noticed though was that on one of my fields
when adding in the 3rd column to the combo box i forgot to set the
column count field to 3 and accidently left it as 2 where the bound
column is 3. and for that field the filter works on the all and blank
selections, but I get a "Run-time error '2001'; You cancelled the
previous operation." when I select anything else.  maybe because the
dates in the combo box arn't truely date values?? but I'm only
guessing :)
Poal.- Hide quoted text -
- Show quoted text -

I've also noticed that in debug mode the values getting passed into
the function are in american format(mm/dd/yyyy). I have no idea if
this will affect whats going on or not. I'll just carry on playing
with it and see where I get :)- Hide quoted text -

- Show quoted text -

I worked it out in the end. Once I replaced all of the " " with # # I
noticed the filters only worked on dates like 01/01/2008 and
05/05/2008 and I soon realised that the american date foprmat was this
issue so I've changed the dates in my union query to 01/01/1900 and
02/02/1900 to avoid this problem and put in format(blah,"mm/dd/yyyy")
in various places in the function to get the IF comparisons the match.

was a pain to get working so thanks for your help!!

I'm not even going to try to attempt on updating the combos with only
filtered record fields.. that sounds like a task too many for me.

Thanks again Doug!
 
Joined
Jul 14, 2013
Messages
1
Reaction score
0
hello
I have question. I stuck with same problem on my database what you had couple years ago could you help me out with it?
 

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