473,568 Members | 2,986 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Filter search based on subform

7 New Member
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 987

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

Similar topics

1
7837
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 from queries. Let me just add that Allen Browne excellent article about this subject may not apply to this scenario on an elementary level. (Here's...
2
2600
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 have incorporated some VB6 code as well as some Conditional Formatting. The code automatically updates CheckBoxes in the SubForm, depending on exam...
3
2756
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 different table ie subform1 based on Table2, subform2 based on Table3 and subform3 based on Table4. I want the user to be able to use the Filter By...
1
1671
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 based on account numbers and then I want another subform based on duplicate entries of an account related to the one on the 1st subform. Is there a...
3
11946
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 subform..... This MSDN article however makes it sound as simple as clicking "Filter by Form", entering the search criterial in the form and/or...
9
15831
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 (actually list boxes) that are multiselects in my main form. I need to use these combo boxes to filter a subform within my main form. My combo...
27
4379
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 if you're in a hurry at all....! I have a Main Form, based upon my main table (products). This main form has a subform (based upon a query that is...
1
2857
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 the main form. One (combo box) filters the other. I would like for both boxes to filter the subforms which by the way are on tab controls I have 8...
1
6784
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 bits of code for different examples. I have one last thing to finish. I am trying to create a search form that will allow users to select criteria from...
0
7605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7917
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8118
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
5501
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1207
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.