Results 1 to 10 of 10
  1. #1
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102

    ComboBox multiple selection


    Hi all, is it possible to use a combo box to search in multiple fields and display a record?
    I am using the combo box wizard to search for records in a table on a form and display that record, but the table has multiple columns that may have info that needs to be displayed, for example:

    field 1=registration, field 2=special code, field 3= plant registration.

    When I receive a job card for a service etc the workshop sometimes use the plant registration or the registration and sometimes the special code, so I need to be able to type in the combo box any one of the three and display that record.

    Please feel free to ask any questions if you do not understand.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    You need code to look at all 3 combos to create the filter.
    Code:
    sub combo1_afterupdate()
      FilterItems
    end sub
    
    sub combo2_afterupdate()
      FilterItems
    end sub
    
    sub combo3_afterupdate()
      FilterItems
    end sub
    
    sub FilterItems()
    dim sWhere as string
    
    if not IsNull(combo1) then    sWhere =sWhere & " and [field1]='" & combo1 & "'"
    if not IsNull(combo2) then    sWhere =sWhere & " and [field2]='" & combo2 & "'"
    if not IsNull(combo3) then    sWhere =sWhere & " and [field3]='" & combo3 & "'"
      
    if sWhere ="" then
       me.filterOn = false
    else
       'remove 1st 'and '
       sWhere = mid(sWhere,5)  
       me.filter = sWhere
       me.filterOn = true
    endif
    
    end sub

  3. #3
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    Hi Ranman256, thanks for you reply, however I am only using one combo with all three fields, should I be creating three combos? Sorry but a little confused here.

  4. #4
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    try

    sWhere ="[field1]='" & combo1 & "' OR [field2]='" & combo1 & "' OR [field3]='" & combo1 & "'"

  5. #5
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    Thanks but it is still only looking up the first column, I want the search criteria to look in all three columns and return the record.

  6. #6
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Why would the same data be in 3 columns?

  7. #7
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    Thanks but it is still only looking up the first column
    The OR means it will look in all 3 columns - what is your actual code you are using

  8. #8
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    Private Sub Combo53_AfterUpdate()
    DoCmd.SearchForRecord , "", acFirst, "[Unitid] = " & Str(Nz(Screen.ActiveControl, 0))
    sWhere = "[unit]='" & Combo53 & "' OR [murphycode]='" & Combo53 & "' OR [plant registration]='" & Combo53 & "'"
    End Sub

  9. #9
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,936
    now totally confused - your searchforrecord will only find the first record on unitid and you have just assigned what we advised to a string called swhere and is not used in your searchforrecord and you have ignored Ranmans additional code.

    Further your searchforrecord is searching on a field called unitid and your swhere is referencing a field called unit. I'm assuming this is a typo


    Code:
    Private Sub Combo53_AfterUpdate()
     Dim sWhere as string
    
         sWhere = "[unit]='" & Combo53 & "' OR [murphycode]='" & Combo53 & "' OR [plant registration]='" & Combo53 & "'"
         DoCmd.SearchForRecord , "", acFirst, sWhere
         
      End Sub

  10. #10
    tonycl69 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Nov 2012
    Posts
    102
    Hi and thanks for that, I realise your confusion but I was not using three combo boxes just one, as you can probably tell I am very new to coding.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 05-10-2016, 05:35 PM
  2. Replies: 1
    Last Post: 04-13-2016, 09:02 PM
  3. Replies: 2
    Last Post: 08-22-2014, 01:20 PM
  4. Replies: 0
    Last Post: 08-24-2010, 06:38 PM
  5. Replies: 0
    Last Post: 12-16-2009, 01:14 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums