473,394 Members | 1,893 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Apply form filter to a underlying query

121 100+
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

Expand|Select|Wrap|Line Numbers
  1. On Error GoTo Error_EquipFilter
  2.  
  3.    Dim FilterClause As String, D As Long
  4.  
  5. D = Me.DirectionGrp.Value
  6.  
  7.  
  8. If Len(Me.CboCat.Value & "") > 0 Then
  9.     If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
  10.     FilterClause = FilterClause & " Category =" & Me.CboCat.Value
  11. End If
  12.  
  13. If Len(Me.CboModel.Value & "") > 0 Then
  14.     If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
  15.     FilterClause = FilterClause & " Model ='" & Me.CboModel.Value & "'"
  16. End If
  17. & "[Treatment]='" & Me.Treatment.Value & "'"
  18.  
  19. If Len(Me.CboManu.Value & "") > 0 Then
  20.     If FilterClause <> "" Then FilterClause = FilterClause & IIf(D = 1, " AND ", " OR ")
  21.     FilterClause = FilterClause & " Manufacturer ='" & Me.CboManu.Value & "'"
  22. End If
  23.  
  24.    CurrentFilter = FilterClause: FilterClause = ""
  25.  
  26.     Forms("frmEquipBooking").Form.Filter = CurrentFilter
  27.     Forms("frmEquipBooking").Form.FilterOn = True
  28.  
  29. Exit_EquipFilter:
  30.    Exit Function
  31.  
  32. Error_EquipFilter:
  33.    MsgBox "EquipFilter Function Error" & vbCr & vbCr & _
  34.           Err.Number & " - " & Err.Description, vbExclamation, _
  35.           "Equipment Filter Error"
  36.    Resume Exit_EquipFilter
  37.  
Any help is much appreciated

Regards Phill
Oct 22 '09 #1
5 5497
ChipR
1,287 Expert 1GB
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?
Oct 22 '09 #2
NeoPa
32,556 Expert Mod 16PB
What Chip said.

I'm equally confused by your question.
Oct 23 '09 #3
phill86
121 100+
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
Oct 27 '09 #4
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 :
  1. Update the WHERE clause of the query to include the extra filtering.
  2. Encapsulate the query in some simple SQL that selects * from your query.
    Assuming your filter has already been prepared in a string strFilter then :
    Expand|Select|Wrap|Line Numbers
    1. strSQL = "SELECT *" & vbCrLf & _
    2.          "FROM   [YourQuery]" & vbCrLf & _
    3.          "WHERE  " & strFilter
.
Oct 27 '09 #5
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.
Oct 27 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
16
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...
9
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...
2
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...
13
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...
1
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...
7
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...
6
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...
1
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
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...
0
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
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...
0
jinu1996
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...
0
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.