473,385 Members | 1,769 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,385 software developers and data experts.

filter results based on multiple criteria

80
Ok, I know I've seen how to do this somewhere but I can't seem to find it again...

My setup is I have a form that has 5 text boxes and 1 check box. "txtFirstName", "txtLastName", "txtDelDate", "txtPickupDate", "txtOrderNumber", and "chkAll". I also have a subform that lists all open order numbers, "Open Order Subform".

I'm trying to have it where I can type a last name and a delivery date and have that filter the results that show up on the sub form.

TIA
Aug 10 '07 #1
7 8019
Rabbit
12,516 Expert Mod 8TB
Ok, I know I've seen how to do this somewhere but I can't seem to find it again...

My setup is I have a form that has 5 text boxes and 1 check box. "txtFirstName", "txtLastName", "txtDelDate", "txtPickupDate", "txtOrderNumber", and "chkAll". I also have a subform that lists all open order numbers, "Open Order Subform".

I'm trying to have it where I can type a last name and a delivery date and have that filter the results that show up on the sub form.

TIA
Does LastName and DeliveryDate make a unique pair?
Aug 10 '07 #2
Scotter
80
Hi, I was just using last name and delivery date as an example. Im not 100% sure what you mean by unique pair, but i would guess that means theres only one combination of the 2. If thats correct, then maby, but not necasarily. All I'm trying to do is filter the list of Open Orders down to a managable number. It would be like if I opend the query behind the form and typed in "Bill" in the First Name criteria, and "Johnson" in the last name criteria so I would only see the open orders that Bill Johnson has.
Aug 10 '07 #3
Rabbit
12,516 Expert Mod 8TB
If you're doing it through a subform, maybe you can just set up the parent/child properties to automatically filter.

If not you can always use the Filter property of the form.
Aug 10 '07 #4
Scotter
80
The text boxes for the main form search criteria are unbound. So linking them together wouldn't work right?

It seems to me like it should be something like,

Expand|Select|Wrap|Line Numbers
  1. Dim search1 As String
  2. Dim search2 As String
  3. Dim search3 As String
  4. Dim search4 As String
  5.  
  6. search1=Me!txtFirstName.value
  7. search2=Me!txtLastName.value
  8. search3=Me!txtDelDate.value
  9. search4=Me!txtPickupDate.value
  10.  
  11. Me!Open_Orders_Subform.Filter = "[First Name]= " & search1
  12. Me!Open_Orders_Subform.Filter = "[Last Name]= " & search2
  13. Me!Open_Orders_Subform.Filter = "[Delivery Date]= " & search3
  14. Me!Open_Orders_Subform.Filter = "[Pickup Date]= " & search4
  15.  
  16. Me!Open_Orders_Subform.FilterOn = True
  17.  
But that isn't workin. Is it even close, or on the right track?
Aug 10 '07 #5
Rabbit
12,516 Expert Mod 8TB
The text boxes for the main form search criteria are unbound. So linking them together wouldn't work right?

It seems to me like it should be something like,

Expand|Select|Wrap|Line Numbers
  1. Dim search1 As String
  2. Dim search2 As String
  3. Dim search3 As String
  4. Dim search4 As String
  5.  
  6. search1=Me!txtFirstName.value
  7. search2=Me!txtLastName.value
  8. search3=Me!txtDelDate.value
  9. search4=Me!txtPickupDate.value
  10.  
  11. Me!Open_Orders_Subform.Filter = "[First Name]= " & search1
  12. Me!Open_Orders_Subform.Filter = "[Last Name]= " & search2
  13. Me!Open_Orders_Subform.Filter = "[Delivery Date]= " & search3
  14. Me!Open_Orders_Subform.Filter = "[Pickup Date]= " & search4
  15.  
  16. Me!Open_Orders_Subform.FilterOn = True
  17.  
But that isn't workin. Is it even close, or on the right track?
Not quite. To reference the filter you should use Me.SubformName.Form.Filter and Me.SubformName.Form.FilterOn

Strings need to be surrounded by single quotes:
Expand|Select|Wrap|Line Numbers
  1. "[First Name] = '" & search1 & "'"
For dates you use pound (#) characters.

To string together multiple search criteria you need to append and use the keyword AND.

SomeString = "[First Name] = 'Bill'"
SomeString = SomeString & " AND [Last Name] = 'Stuckman'"

You'll also need to think about cases where the user leaves the field blank. So you'll probably need to throw in some If statements.
Aug 10 '07 #6
Scotter
80
Ok, This is how I got mine to work;

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command18_Click()
  2.  
  3. Dim searchfor As String
  4. Dim search1 As String
  5. Dim search2 As String
  6. Dim search3 As String
  7. Dim search4 As String
  8.  
  9.  If IsNull(first) = False Then
  10.        search1 = Me.first.Value
  11.        searchfor = ""
  12.        searchfor = "[First Name] = '" & search1 & "'"
  13.  End If
  14.  If IsNull(last) = False Then
  15.       search2 = Me.last.Value
  16.       searchfor = searchfor & "AND [Last Name] = '" & search2 & "'"
  17.             If IsNull(first) = True Then
  18.             searchfor = ""
  19.             searchfor = searchfor & "[Last Name] = '" & search2 & "'"
  20.             End If
  21.  End If
  22.  If IsNull(Phone) = False Then
  23.       search3 = Me.Phone.Value
  24.       searchfor = searchfor & "AND [Phone] = '" & search3 & "'"
  25.            If IsNull(last) = True Then
  26.            searchfor = ""
  27.            searchfor = searchfor & "[Phone] = '" & search3 & "'"
  28.            End If
  29.  End If
  30.  If IsNull(email) = False Then
  31.       search4 = Me.email.Value
  32.       searchfor = searchfor & "AND [email] = '" & search4 & "'"
  33.            If IsNull(Phone) = True Then
  34.            searchfor = ""
  35.            searchfor = searchfor & "[email] = '" & search4 & "'"
  36.            End If
  37.  End If
  38.  
  39.  Me.[CUST_NAME subform].Form.Filter = searchfor
  40.  Me.[CUST_NAME subform].Form.FilterOn = True
  41.  
  42. End Sub
  43.  
Thanks so much for al your help Rabbit
Aug 22 '07 #7
Rabbit
12,516 Expert Mod 8TB
Not a problem. Good luck.
Aug 22 '07 #8

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

Similar topics

1
by: Johan | last post by:
I have made a form (filterform) where I can select 3 conditions, to open another form (showrecords), filtered with the 3 conditions. On the filterform: 3 drop down boxes, where the user kan...
0
by: CSDunn | last post by:
Hello, I have a problem with field filtering between an Access 2000 Project form (the application is called CELDT), and the report that shows the results of the filter. Both the form and the...
6
by: Ralph2 | last post by:
Some time ago with a lot of help from this group I made a reasonably successful database to keep track of our shop drawings. However the searching mechanism is too complicated for the occasional...
14
by: Anja | last post by:
Hi everyone, I have a sub form that references a query to get the results. However, what I want to do is filter the results further based on a certain criteria. How can I tell the sub form to...
1
by: Barb.Richards | last post by:
I have created an append query that pulls information from one database, and will append the selected information into a new table. The fields are setup like 'number' 'category' 'code' 'shares' and...
3
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
1
by: jcf378 | last post by:
Hi all-- Does anyone have any insight as to how I might create a search form that allows a user to select criteria based on any related table in the whole database. The search form I have now only...
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: woodey2002 | last post by:
Hi Everyone and many thanks for your time.. I am trying to begin access and a bit of VBA i am enjoying it but I have a annoying problem I just can’t get any where on. My databse mostly includes...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...

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.