Hi,
I have a form that I have applied a filter to by using combo boxes which works fine.
Is there a way to apply that filter to the forms underlying query
Here is the code that I use to filter the form -
On Error GoTo Error_EquipFilter
-
-
Dim FilterClause As String, D As Long
-
-
D = Me.DirectionGrp.Value
-
-
-
If Len(Me.CboCat.Value & "") > 0 Then
-
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
-
FilterClause = FilterClause & " Category =" & Me.CboCat.Value
-
End If
-
-
If Len(Me.CboModel.Value & "") > 0 Then
-
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
-
FilterClause = FilterClause & " Model ='" & Me.CboModel.Value & "'"
-
End If
-
& "[Treatment]='" & Me.Treatment.Value & "'"
-
-
If Len(Me.CboManu.Value & "") > 0 Then
-
If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
-
FilterClause = FilterClause & " Manufacturer ='" & Me.CboManu.Value & "'"
-
End If
-
-
CurrentFilter = FilterClause: FilterClause = ""
-
-
Forms("frmEquipBooking").Form.Filter = CurrentFilter
-
Forms("frmEquipBooking").Form.FilterOn = True
-
-
Exit_EquipFilter:
-
Exit Function
-
-
Error_EquipFilter:
-
MsgBox "EquipFilter Function Error" & vbCr & vbCr & _
-
Err.Number & " - " & Err.Description, vbExclamation, _
-
"Equipment Filter Error"
-
Resume Exit_EquipFilter
-
Any help is much appreciated
Regards Phill
5 5497
What do you mean when you say "apply that filter to the form's underlying query"? From my perspective, that's exactly what you're doing. Did you want to save the filter permanently as part of the query?
NeoPa 32,556
Expert Mod 16PB
What Chip said.
I'm equally confused by your question.
Hi,
Thanks for the response and apologies for not getting back to you sooner.
I am using that query elsewhere in a recordset and when the query is run from within the recordset the filter that is applied to the form does not affect the query that is in the recordset.
Which I guess would make sense I just need to know how to apply the filter that I have applied on the forrm to the query on its own.
Hope this makes more sense sorry for any confusion caused.
Regards Phill
NeoPa 32,556
Expert Mod 16PB
That rather depends on how you're using the query in your Recordset code.
Generally you can do it one of two ways : - Update the WHERE clause of the query to include the extra filtering.
- Encapsulate the query in some simple SQL that selects * from your query.
Assuming your filter has already been prepared in a string strFilter then : - strSQL = "SELECT *" & vbCrLf & _
-
"FROM [YourQuery]" & vbCrLf & _
-
"WHERE " & strFilter
.
NeoPa 32,556
Expert Mod 16PB
Phill, can I make a friendly suggestion relating to coding style, particularly when posting in forum :
It's generally worth starting new VBA commands on a separate line in your modules, rather than using the line separation character (:). It's fine for use in the Immediate Pane of the VBA IDE (See Debugging in VBA), but it can cause confusion when used elsewhere.
I'm referring of course to your line #24.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Terry |
last post by:
I have cerated a Form, ExamsFrm, which is used to input details of
exams taken at several Centres. It dosplays details from StudentTbl
and has a SubForm which displays details from ExamsTble.
I...
|
by: Nhmiller |
last post by:
I already have a report designed under Reports. When I use filtering in Forms
or Tables, I see no way to select that filtered list when I am in Reports, and
there appears to be no way to do the...
|
by: David White |
last post by:
Hello everyone,
I'm new to access, so if this is a dumb question I apologize in
advance.
I created a query that requires a "parameter value" to be entered.
I then created a form to display...
|
by: Arnold |
last post by:
Greetings Gurus,
In a report showing the names of students and their progress, I am
getting an error in the name field (Name: #Error). The report gets its
data from an unbound form containing...
|
by: salad |
last post by:
Operating in A97.
I didn't receive much of a response conserning Pivot tables in Access.
Pivot tables are nice, but a CrossTab will work for me too.
Using a Pivot table, one is actually...
|
by: mattscho |
last post by:
Re: Filter By From, Apply Filter, Remove Filter Buttons in a Form.
--------------------------------------------------------------------------------
Hi All, Trying to create a set of 3 buttons in...
|
by: Ceebaby via AccessMonster.com |
last post by:
Hi All
Here's hoping someone can help me with this.
I have a report based on a query where the criteria for 4 of the fields is
set from an unbound form. I want the user to be able to select any...
|
by: jmarcrum |
last post by:
Hi!
I have created a Union Query in ACCESS 2003, that combines 130 records from one query (Extra Foreman Radios) and 250 records from another query (Forman Main Radios). I have created a...
|
by: c0l0nelFlagg |
last post by:
I need to display a main form with 48 identical subforms. 6 columns with
8 rows.
I set up a separate query for each subform, identical in structure and
underlying data except the criteria in...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
| |