473,405 Members | 2,261 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,405 software developers and data experts.

Filtering forms

Hi,
I was wondering if you could help me with a problem. I have 2 combos in an access form and I would like to be able to filter based on both of them.
My first combo has usernames and the second one has company names. So I would like users to be able to pick their name from the first drop down and then pick the company name from the second drop down list so they can see what issues for that company are assigned to them.

I am currently filtering each one using this method as recommended in a previous post:
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboCompany_AfterUpdate() 
  2. If Not IsNull(Me![cboCompany]) Then 
  3.   Me.Filter = "[Company]='" & Me![cboCompany] & "'" 
  4.   Me.FilterOn = True 
  5. End If 
  6. End Sub
It works great if I only want to filter one at a time.
Any help you can provide is great! I am using access 2007.
Thanks!
Jan 7 '09 #1
3 1822
MikeTheBike
639 Expert 512MB
@linwork
Hi

Perhaps something like this
Expand|Select|Wrap|Line Numbers
  1. Private Sub cboCompany_AfterUpdate()
  2.     SetFilter
  3. End Sub
  4. Private Sub cboUsername_AfterUpdate()
  5.     SetFilter
  6. End Sub
  7. Private Sub SetFilter()
  8.     Dim FilterCriteria As String
  9.     If cboCompany & "" <> "" Then FilterCriteria = FilterCriteria & " AND [Company]='" & cboCompany & "'"
  10.     If cboUsername & "" <> "" Then FilterCriteria = FilterCriteria & " AND [Username]='" & cboUsername & "'"
  11.     If FilterCriteria = "" Then
  12.             Me.FilterOn = False
  13.     Else
  14.         FilterCriteria = Mid(FilterCriteria, 6) 'REMOVE THE LEADING " AND "
  15.         Me.Filter = FilterCriteria
  16.         Me.FilterOn = True
  17.     End If
  18. End Sub
(disclaimer!)
Note: Untried air code.

MTB

(ps. I know there is some redundant code in the first IF statment, but it does mean you can add criteria anywhere without worrying!!)
Jan 8 '09 #2
This works perfectly. Thank MTB!
Jan 8 '09 #3
NeoPa
32,556 Expert Mod 16PB
A tutorial related to this can be found at Example Filtering on a Form.

I doubt you'll need it as MTB has clearly answered your question, however other searchers may be interested hence the post.

Welcome to Bytes!
Jan 8 '09 #4

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

Similar topics

19
by: William Wisnieski | last post by:
Hello Everyone, I have a main form with a datasheet subform that I use to query by form. After the user selects two criteria on the main form and clicks the cmdShowResults button on the main...
7
by: Nathan Bloomfield | last post by:
Hi All, I am hoping someone out there will be kind enough to find out where my code is going wrong. The current code is inefficiant but hopefully it will convey the data I require to be...
4
by: Doug | last post by:
I have your typically form/subform. You enter the account number in a textbox and select whether you want to see the detail or summary information on the main form. Both fields I want to filter...
15
by: Richard Hollenbeck | last post by:
I tried to ask this question before on the 14th of January but I never got a reply. I'm still struggling with the problem. I'll try to rephrase the question: I have a crosstab query with rows...
1
by: mstery | last post by:
I have a report generated via an ID selection made in a dropdown on a form. The report filters by an on click event in a preview report button on the form. Everything in the report, including...
8
by: | last post by:
hi, i have a form on which a user can choose specific criteria such as dates etc, in order to filter the report that is called from the form. i do this by using the Where section of the...
19
by: Chantelle | last post by:
I've got this A2K DB that has a continuous form that lists Suppliers and their details. The form has a field for each supplier that holds several Keywords that reflect the suppliers products or...
8
by: Ragbrai | last post by:
Howdy All, I have a query that is used for filtering results to be used in a combo box. The query needs to test fields from both a table and then unbound text boxes on the form that also contains...
3
by: Harry Haller | last post by:
Hello, I want to implement a generic list which will be used to display 7 columns in a GridView. One should be able to sort, filter and page each of the 7 columns. Ideally the filter should be...
10
by: Redbeard | last post by:
Hi, I am a newbie using Access 2003. I am trying to apply a filter to a form and then re-filtering that forms records again. Basically I have my main form and when I wish to filter I click a button...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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:
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.