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

Criteria form for query

83
I have a form that has unbound controls. There is a check filter-query def.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckFilter()
  2.     Dim strFilter As String, strOldFilter As String
  3.        strOldFilter = Me.Filter
  4.         If Me.LSI_Case_Number > "" Then _
  5.             strFilter = strFilter & _
  6.                     " AND ( [LSI Case Number] LIKE '" & Me.LSI_Case_Number & "')"
  7.         If Me.Broker > "" Then _
  8.              strFilter = strFilter & _
  9.                     " AND ([Broker]='" & Me.Broker & "')"
  10.  
  11.          If Me.Insured_Name > "" Then _
  12.             strFilter = strFilter & _
  13.                     " AND ([Insured Name] Like '" & Me.Insured_Name & "')"
  14.           If Me.Agemin > "" Then _
  15.              strFilter = strFilter & _
  16.                     " AND ([Age]='" & Me.Agemin & "')"
  17.           If Me.agemax > "" Then _
  18.              strFilter = strFilter & _
  19.                     " AND ([Age]='" & Me.agemax & "')"
  20.  
  21.     If strFilter > "" Then strFilter = Mid(strFilter, 6)
  22.     If strFilter <> strOldFilter Then
  23.         Me.Filter = strFilter
  24.         Me.FilterOn = (strFilter > "")
  25.         qdf.SQL = strFilter
  26.     End If
  27. qdf.Close
  28. End Sub
  29.  
Then, in the query I used these unbound controls in the criteria statement. The query only works when I have all the values in the form filled out. If one is empty then the query will not work. One of the criteria statements look like this:
IIf(IsNull([Forms]![Query]![Broker]),"",[Forms]![Query]![Broker]). It still prompts me to fill in a value for broker when I open the query.
I don't know where to go from here.
Apr 24 '07 #1
5 1683
MMcCarthy
14,534 Expert Mod 8TB
Try this ...
Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckFilter()
  2.     Dim strFilter As String, strOldFilter As String
  3.        strOldFilter = Me.Filter
  4.         If Me.LSI_Case_Number <> "" Then _
  5.             strFilter = strFilter & _
  6.                     " AND ( [LSI Case Number] LIKE '" & Me.LSI_Case_Number & "')"
  7.         If Me.Broker <> "" Then _
  8.              strFilter = strFilter & _
  9.                     " AND ([Broker]='" & Me.Broker & "')"
  10.  
  11.          If Me.Insured_Name <> "" Then _
  12.             strFilter = strFilter & _
  13.                     " AND ([Insured Name] Like '" & Me.Insured_Name & "')"
  14.           If Me.Agemin <> "" Then _
  15.              strFilter = strFilter & _
  16.                     " AND ([Age]='" & Me.Agemin & "')"
  17.           If Me.agemax <> "" Then _
  18.              strFilter = strFilter & _
  19.                     " AND ([Age]='" & Me.agemax & "')"
  20.  
  21.     If strFilter <> "" Then strFilter = Mid(strFilter, 6)
  22.     If strFilter <> strOldFilter Then
  23.         Me.Filter = strFilter
  24.         Me.FilterOn = (strFilter <> "")
  25.         qdf.SQL = strFilter
  26.     End If
  27. qdf.Close
  28. End Sub
  29.  
Apr 25 '07 #2
jl2886
83
Thanks, but it still prompts me for the value when the form value is empty. Is there anything else I can try?

Try this ...
Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckFilter()
  2.     Dim strFilter As String, strOldFilter As String
  3.        strOldFilter = Me.Filter
  4.         If Me.LSI_Case_Number <> "" Then _
  5.             strFilter = strFilter & _
  6.                     " AND ( [LSI Case Number] LIKE '" & Me.LSI_Case_Number & "')"
  7.         If Me.Broker <> "" Then _
  8.              strFilter = strFilter & _
  9.                     " AND ([Broker]='" & Me.Broker & "')"
  10.  
  11.          If Me.Insured_Name <> "" Then _
  12.             strFilter = strFilter & _
  13.                     " AND ([Insured Name] Like '" & Me.Insured_Name & "')"
  14.           If Me.Agemin <> "" Then _
  15.              strFilter = strFilter & _
  16.                     " AND ([Age]='" & Me.Agemin & "')"
  17.           If Me.agemax <> "" Then _
  18.              strFilter = strFilter & _
  19.                     " AND ([Age]='" & Me.agemax & "')"
  20.  
  21.     If strFilter <> "" Then strFilter = Mid(strFilter, 6)
  22.     If strFilter <> strOldFilter Then
  23.         Me.Filter = strFilter
  24.         Me.FilterOn = (strFilter <> "")
  25.         qdf.SQL = strFilter
  26.     End If
  27. qdf.Close
  28. End Sub
  29.  
Apr 25 '07 #3
MMcCarthy
14,534 Expert Mod 8TB
Try this ...
Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckFilter()
  2.     Dim strFilter As String, strOldFilter As String
  3.        strOldFilter = Me.Filter
  4.         If Not IsNull(Me.LSI_Case_Number) Then _
  5.             strFilter = strFilter & _
  6.                     " AND ( [LSI Case Number] LIKE '" & Me.LSI_Case_Number & "')"
  7.         If Not IsNull(Me.Broker) Then _
  8.              strFilter = strFilter & _
  9.                     " AND ([Broker]='" & Me.Broker & "')"
  10.  
  11.          If Not IsNull(Me.Insured_Name) Then _
  12.             strFilter = strFilter & _
  13.                     " AND ([Insured Name] Like '" & Me.Insured_Name & "')"
  14.           If Not IsNull(Me.Agemin) Then _
  15.              strFilter = strFilter & _
  16.                     " AND ([Age]='" & Me.Agemin & "')"
  17.           If Not IsNull(Me.agemax) Then _
  18.              strFilter = strFilter & _
  19.                     " AND ([Age]='" & Me.agemax & "')"
  20.  
  21.     If strFilter <> "" Then strFilter = Mid(strFilter, 6)
  22.     If strFilter <> strOldFilter Then
  23.         Me.Filter = strFilter
  24.         Me.FilterOn = (strFilter <> "")
  25.         qdf.SQL = strFilter
  26.     End If
  27. qdf.Close
  28. End Sub
  29.  
Apr 25 '07 #4
jl2886
83
I think it has something to do with with the criteria expression because it is not working. mmcarthy, thank you for always trying to help me.

Try this ...
Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckFilter()
  2.     Dim strFilter As String, strOldFilter As String
  3.        strOldFilter = Me.Filter
  4.         If Not IsNull(Me.LSI_Case_Number) Then _
  5.             strFilter = strFilter & _
  6.                     " AND ( [LSI Case Number] LIKE '" & Me.LSI_Case_Number & "')"
  7.         If Not IsNull(Me.Broker) Then _
  8.              strFilter = strFilter & _
  9.                     " AND ([Broker]='" & Me.Broker & "')"
  10.  
  11.          If Not IsNull(Me.Insured_Name) Then _
  12.             strFilter = strFilter & _
  13.                     " AND ([Insured Name] Like '" & Me.Insured_Name & "')"
  14.           If Not IsNull(Me.Agemin) Then _
  15.              strFilter = strFilter & _
  16.                     " AND ([Age]='" & Me.Agemin & "')"
  17.           If Not IsNull(Me.agemax) Then _
  18.              strFilter = strFilter & _
  19.                     " AND ([Age]='" & Me.agemax & "')"
  20.  
  21.     If strFilter <> "" Then strFilter = Mid(strFilter, 6)
  22.     If strFilter <> strOldFilter Then
  23.         Me.Filter = strFilter
  24.         Me.FilterOn = (strFilter <> "")
  25.         qdf.SQL = strFilter
  26.     End If
  27. qdf.Close
  28. End Sub
  29.  
Apr 25 '07 #5
MMcCarthy
14,534 Expert Mod 8TB
I think it has something to do with with the criteria expression because it is not working. mmcarthy, thank you for always trying to help me.
You've enclosed all the textbox values with single quotes. This indicates that they are all text fields. Is this the case?
Apr 25 '07 #6

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

Similar topics

2
by: neptune | last post by:
I have a query where each customer has an or . Sometimes both fields for a customer are populated, but if is null, then will be populated and vice versa. I have a form, , where I select a...
2
by: Matthew | last post by:
Hey , I have built a query which takes values from unbounded fields on a form, and it all works except for one thing. I have a few fields in my query that are dates. I also have a start and...
3
by: pelcovits | last post by:
I am trying to set up an unbound form to enter report criteria. I've followed the MS Office Assistance document: "Create a form to enter report criteria" which describes how to enter data (such...
0
by: MLH | last post by:
I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the selections made in a number of criteria choices on a form, a field on the form will have string...
3
by: MLH | last post by:
Am repeating question with different subject heading, perhaps stating more clearly my problem... I have an A97 query (qryVehiclesNowners2) that has a table field in it named . Depending on the...
4
by: meganrobertson22 | last post by:
Hi Everyone- I have a question about how to add and then use the "All" selection in a combo box. I am trying to figure out how to: (1) add "All" as a selection to a combo box and then (2)...
2
by: Mark Roughton | last post by:
I have a form where the users need to view records for various criteria, one of which is a date field on which they may wish to view all related data for the selected date, for all dates upto and...
3
by: rhobson2 | last post by:
Hello, I wrote a database applicaiton using Access XP (2002) and everything has been working good for the client until they purchased a couple of new computers with Access 2003. The meetings...
49
by: martin DH | last post by:
Hello all, I'm back with another SQL related problem. The details are below, but in short: I am using Access 2003. I have a table whose structure may include four different associate names per...
17
by: sharsy | last post by:
Hello guys, I would like some help in generating query criteria that will identify credit cards that have expired on an access database. The specific Field is formatted with a Data Type of...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...
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
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.