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

Filter search based on subform

I have the following code in my program allowing users to search for entries matching up to five different criteria at once. I changed the form to now contain a subform and would like to allow the users to search by fields contained in the subform. The field on the subform that I would like to include in the search is [Presentation], but just including [Presentation] in the code did not do the trick -the search was not recognizing the subform field [Presentation]. The code is pasted below:

Expand|Select|Wrap|Line Numbers
  1. Private Sub cmdInitiate_Search_Click()
  2. On Error GoTo Err_cmdInitiate_Search_Click
  3.  
  4.     Dim strCriteria(5) As String
  5.     Dim strSearchField(5) As String
  6.     Dim LinkCriteria(5) As String
  7.     Dim LinkCriteriaFinal As String
  8.     Dim strSQL As String
  9.     Dim i As Integer
  10.  
  11.     If IsNull(Me!criteria1) Then
  12.         MsgBox "Please enter valid search criteria.", vbCritical, "Error"
  13.         Me![criteria1].SetFocus
  14.         Exit Sub
  15.     Else
  16.         strCriteria(0) = Me![criteria1]
  17.     End If
  18.     If Not IsNull(Me![Criteria2]) Then
  19.         strCriteria(1) = Me![Criteria2]
  20.     Else
  21.         strCriteria(1) = Me![criteria1]
  22.     End If
  23.     If Not IsNull(Me![Criteria3]) Then
  24.         strCriteria(2) = Me![Criteria3]
  25.     Else
  26.         strCriteria(2) = Me![criteria1]
  27.     End If
  28.     If Not IsNull(Me![Criteria4]) Then
  29.         strCriteria(3) = Me![Criteria4]
  30.     Else
  31.         strCriteria(3) = Me![criteria1]
  32.     End If
  33.     If Not IsNull(Me![Criteria5]) Then
  34.         strCriteria(4) = Me![Criteria5]
  35.     Else
  36.         strCriteria(4) = Me![criteria1]
  37.     End If
  38.  
  39.     If IsNull(Me!SearchField1) Then
  40.         MsgBox "Please enter valid search field.", vbCritical, "Error"
  41.         Me![SearchField1].SetFocus
  42.         Exit Sub
  43.     Else
  44.         strSearchField(0) = Me![SearchField1]
  45.     End If
  46.     If Not IsNull(Me![SearchField2]) Then
  47.         strSearchField(1) = Me![SearchField2]
  48.     Else
  49.         strSearchField(1) = Me![SearchField1]
  50.     End If
  51.     If Not IsNull(Me![SearchField3]) Then
  52.         strSearchField(2) = Me![SearchField3]
  53.     Else
  54.         strSearchField(2) = Me![SearchField1]
  55.     End If
  56.     If Not IsNull(Me![Searchfield4]) Then
  57.         strSearchField(3) = Me![Searchfield4]
  58.     Else
  59.         strSearchField(3) = Me![SearchField1]
  60.     End If
  61.     If Not IsNull(Me![SearchField5]) Then
  62.         strSearchField(4) = Me![SearchField5]
  63.     Else
  64.         strSearchField(4) = Me![SearchField1]
  65.     End If
  66.  
  67.     Me.Visible = False
  68.  
  69. For i = 0 To 4
  70.     Select Case strSearchField(i)
  71.     Case 1
  72.         LinkCriteria(i) = "[Region]"
  73.     Case 2
  74.         LinkCriteria(i) = "[Firm_Name]"
  75.     Case 3
  76.         LinkCriteria(i) = "[Address_1]"
  77.     Case 4
  78.         LinkCriteria(i) = "[Address_2]"
  79.     Case 5
  80.         LinkCriteria(i) = "[Contact]"
  81.     Case 6
  82.         LinkCriteria(i) = "[City]"
  83.     Case 7
  84.         LinkCriteria(i) = "[State]"
  85.     Case 8
  86.         LinkCriteria(i) = "[Zip]"
  87.     Case 9
  88.         LinkCriteria(i) = "[County]"
  89.     Case 10
  90.         LinkCriteria(i) = "[Country]"
  91.     Case 11
  92.         LinkCriteria(i) = "[Orig_Info]"
  93.     Case 12
  94.         LinkCriteria(i) = "[Last_Update]"
  95.     Case 13
  96.         LinkCriteria(i) = "[Firm_Size]"
  97.     Case 14
  98.         LinkCriteria(i) = "[Specialty_Work]"
  99.     Case 15
  100.         LinkCriteria(i) = "[Last_Office_Visit]"
  101.     Case 16
  102.         LinkCriteria(i) = "[Residential]"
  103.     Case 17
  104.         LinkCriteria(i) = "[Type of Operation]"
  105.     Case 18
  106.         LinkCriteria(i) = "[Presentation]"
  107.     Case 19
  108.         LinkCriteria(i) = "[COR200]"
  109.     Case 20
  110.         LinkCriteria(i) = "[COR300]"
  111.     Case 21
  112.         LinkCriteria(i) = "[COR400]"
  113.     Case 22
  114.         LinkCriteria(i) = "[COR500]"
  115.     Case 23
  116.         LinkCriteria(i) = "[Binder Holder?]"
  117.     Case 24
  118.         LinkCriteria(i) = "[Yearly Sales Volume]"
  119.     Case 25
  120.         LinkCriteria(i) = "[Type of Entry]"
  121.     End Select
  122. Next i
  123.  
  124.  
  125. For i = 0 To 4
  126.     If ViewOptions.Value = 1 Then
  127.         If i = 0 Then
  128.             If IsNumeric(strCriteria(i)) Then
  129.                 LinkCriteriaFinal = "(" & LinkCriteria(i) & " like " & strCriteria(i) & " &'*' )"
  130.             Else
  131.                 LinkCriteriaFinal = "(" & LinkCriteria(i) & " like '" & strCriteria(i) & "' &'*' )"
  132.             End If
  133.         Else
  134.             If IsNumeric(strCriteria(i)) Then
  135.                 LinkCriteriaFinal = LinkCriteriaFinal & " and (" & LinkCriteria(i) & " like  " & strCriteria(i) & " & '*' )"
  136.             Else
  137.                 LinkCriteriaFinal = LinkCriteriaFinal & " and (" & LinkCriteria(i) & " like  '" & strCriteria(i) & "' & '*' )"
  138.             End If
  139.         End If
  140.     Else
  141.         If i = 0 Then
  142.             If IsNumeric(strCriteria(i)) Then
  143.                 LinkCriteriaFinal = "(" & LinkCriteria(i) & " like " & strCriteria(i) & " &'*' )"
  144.             Else
  145.                 LinkCriteriaFinal = "(" & LinkCriteria(i) & " like '" & strCriteria(i) & "' &'*' )"
  146.             End If
  147.         Else
  148.             If IsNumeric(strCriteria(i)) Then
  149.                 LinkCriteriaFinal = LinkCriteriaFinal & " or (" & LinkCriteria(i) & " like  " & strCriteria(i) & " & '*' )"
  150.             Else
  151.                 LinkCriteriaFinal = LinkCriteriaFinal & " or (" & LinkCriteria(i) & " like  '" & strCriteria(i) & "' & '*' )"
  152.             End If
  153.         End If
  154.      End If
  155. Next i
  156.  
  157.     MsgBox "The Link Criteria specified is " & LinkCriteriaFinal
  158.  
  159.     Me.Visible = False
  160.  
  161.     DoCmd.OpenForm "QueryResults", , , LinkCriteriaFinal, acFormReadOnly
  162.  
  163.  
  164. Exit_cmdInitiate_Search_Click:
  165.     Exit Sub
  166.  
  167. Err_cmdInitiate_Search_Click:
  168.     MsgBox Error$
  169.     Resume Exit_cmdInitiate_Search_Click
  170.  
  171. End Sub
Any ideas?

Thank you!
Mar 22 '07 #1
0 980

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

Similar topics

1
by: Robert Neville | last post by:
I would like to add filter functionality to my database whether through the Main form or the subform. This question may be rudimentary, yet I have not less experience with filtering data outside...
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...
3
by: Tony Williams | last post by:
Sorry to repost but I cannot work this out. Can anyone come up with a suggestion? I have a main form based on Table1. The form has a tab control of three pages. Each page has a subform based on a...
1
by: dmkeith2 | last post by:
OK, This is what I want to do. I have a main table and several other tables with referential integrity based on the tax ID number. My main form is based on the Main Table, I have a subform...
3
by: dhowell | last post by:
In reading some of the posts on this group, it appears as though it is not strait forward at all to filter a form, which has subforms, by criteria which are either on subforms or span more than one...
9
by: natwong | last post by:
Hi All, I'm a newbie in terms of Access and some of its functionality . I've been stuck on this problem for a couple days, even after searching the Web, etc. Currently I have five combo boxes...
27
stonward
by: stonward | last post by:
Hi again People. This Forum has been a serious help for me...I'm sure you know how it is...you get pretty good at handling Access when wham! you come across something you just can't figure - and...
1
by: kinglioness | last post by:
Hello All, I am new to this forum so I apologize if this quesiton was asked already. Although i did search but i couldn't find. I have 2 combo boxes one unbound and the other bound they are on...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.