Results 1 to 11 of 11
  1. #1
    T_Tronix is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2013
    Posts
    28

    Wildcard within a combobox

    I have a combobox with 2 columns where I manually set the following criteria:



    "E";"English"
    "F";"French"
    "EF";"Bilingual"

    In my employee table under the Languages field I have E,F or EF

    I wanted to display in a sub-form a list of employees who speak a specific language but I can't use a wildcard in the combo-box properties. Basically when someone is looking for an English speaking employee they should get both E and EF employees not only E.

    I tried doing "E*";"English" but it doesn't display anything.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    If you are storing the letters ("E", "F" ,"EF") in the table, then you should be able to use

    in a query
    WHERE YourTableName.Languages Like "E*";

    -------------

    as a filter
    Me.Filter = "Languages Like 'E*'"
    Me.FilterOn = TRUE

    Here is the code I used for an unbound combo box to filter the form
    Code:
    Private Sub Combo3_AfterUpdate()
       'sets a filter
       If Me.Combo3 = "E" Then
          'All English
          Me.Filter = "Languages Like 'E*'"
          Me.FilterOn = True
       ElseIf Me.Combo3 = "F" Then
          'All French
          Me.Filter = "Languages Like 'F*'"
          Me.FilterOn = True
       ElseIf Me.Combo3 = "EF" Then
         ' Bilingual
          Me.Filter = "Languages Like 'EF'"
          Me.FilterOn = True
       End If
    
    End Sub
    Code for a button to clear the filter
    Code:
    Private Sub btnClearFilter_Click()
       Me.Filter = ""
       Me.FilterOn = False
    End Sub

  3. #3
    T_Tronix is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2013
    Posts
    28
    Well its a combobox that displays results in a subform. How do I get into the qury of the combo-box? I initialized the values from its properties window so I did not actually write the code.

    Quote Originally Posted by ssanfu View Post
    If you are storing the letters ("E", "F" ,"EF") in the table, then you should be able to use

    in a query
    WHERE YourTableName.Languages Like "E*";

    -------------

    as a filter
    Me.Filter = "Languages Like 'E*'"
    Me.FilterOn = TRUE

    Here is the code I used for an unbound combo box to filter the form
    Code:
    Private Sub Combo3_AfterUpdate()
       'sets a filter
       If Me.Combo3 = "E" Then
          'All English
          Me.Filter = "Languages Like 'E*'"
          Me.FilterOn = True
       ElseIf Me.Combo3 = "F" Then
          'All French
          Me.Filter = "Languages Like 'F*'"
          Me.FilterOn = True
       ElseIf Me.Combo3 = "EF" Then
         ' Bilingual
          Me.Filter = "Languages Like 'EF'"
          Me.FilterOn = True
       End If
    
    End Sub
    Code for a button to clear the filter
    Code:
    Private Sub btnClearFilter_Click()
       Me.Filter = ""
       Me.FilterOn = False
    End Sub

  4. #4
    T_Tronix is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2013
    Posts
    28
    Not sure I follow the functionality of "filter" how does it update the query result in my subform?

    I inserted the following into my combobox code:

    Code:
    Option Compare Database
    
    Private Sub cmbLanguage_Click()
    Me.Filter = "Languages Like 'E*'"
    Me.FilterOn = True
    End Sub
    
    
    Private Sub cmbLanguage_AfterUpdate()
       'sets a filter
       If Me.cmbLanguage = "E" Then
          'All English
          Me.Filter = "Languages Like 'E*'"
          Me.FilterOn = True
       ElseIf Me.cmbLanguage = "F" Then
          'All French
          Me.Filter = "Languages Like 'F*'"
          Me.FilterOn = True
       ElseIf Me.cmbLanguage = "EF" Then
         ' Bilingual
          Me.Filter = "Languages Like 'EF'"
          Me.FilterOn = True
       End If
    
    
    End Sub

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Is the combobox on the main form or on the subform?

    If it's on the main form that makes it harder to set the Filter and FilterOn properties of subform.

    Is the main form a bound form? Is the subform in datasheet view?

    An alternative to the If Then structure:

    Me.Filter = "Languages Like '*" & Me.combobox & "*'"
    Me.FilterOn
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    T_Tronix is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2013
    Posts
    28
    This is what it looks like, 3 combo-boxes that define what is seen in a subform.

    Click image for larger version. 

Name:	11-21-2013 2-14-13 PM.jpg 
Views:	14 
Size:	61.6 KB 
ID:	14454

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Delete this code:
    Code:
    Private Sub cmbLanguage_Click()
    Me.Filter = "Languages Like 'E*'"
    Me.FilterOn = True
    End Sub
    I was giving you an example of code to filter a form. If you have the combo box on the main form and you want to filter a sub-form, you would have to change the code in the combo box after update event to refer to the sub form.

    So, if the name of the combo box is "cmbLanguage", and the name of the sub form is "Subform1", then the code would be:
    Code:
    Option Compare Database  ' these two lines should be at the top of every module
    Option Explicit     ' these two lines should be at the top of every module
    
    Private Sub cmbLanguage_AfterUpdate()
       'sets a filter
       If Me.cmbLanguage = "E" Then
          'All English
          Me!Subform1.Form.Filter = "[Languages] Like 'E*'"
          Me!Subform1.Form.FilterOn = True
       ElseIf Me.cmbLanguage = "F" Then
          'All French
          Me!Subform1.Form.Filter = "[Languages] Like 'F*'"
          Me!Subform1.Form.FilterOn = True
       ElseIf Me.cmbLanguage = "EF" Then
         ' Bilingual
          Me!Subform1.Form.Filter = "[Languages] Like 'EF'"
          Me!Subform1.Form.FilterOn = True
       End If
    
    
    End Sub
    
    Private Sub btnClearFilter_Click()
       Me.Filter = ""
       Me.FilterOn = False
    End Sub
    See attached mdb.

  8. #8
    T_Tronix is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2013
    Posts
    28
    The problem I'm getting my subform seems to be updated before the filter comes on. Like when I choose English it does not show the EF as part of the list so the filter doesn't even have data to filter.

  9. #9
    T_Tronix is offline Novice
    Windows 8 Access 2007
    Join Date
    Nov 2013
    Posts
    28
    Ok got it, I had to remove the cmbLanguage -> Languages connection from the Link Master to Link Child fields. Now it works

    And a minor fix since French is either EF or F it should be "*F"

    THANKS!

  10. #10
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Good catch.
    Glad you got it functioning

  11. #11
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    Simpler, more flexible code in post 5.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Querying a wildcard
    By undee69 in forum Queries
    Replies: 1
    Last Post: 10-15-2012, 06:00 AM
  2. Wildcard search within ComboBox to control RowSource
    By CaptainKen in forum Programming
    Replies: 22
    Last Post: 05-16-2012, 02:19 PM
  3. Filter with wildcard
    By gg80 in forum Programming
    Replies: 8
    Last Post: 10-07-2011, 06:29 PM
  4. If OR statement (maybe a wildcard?)
    By Lorlai in forum Queries
    Replies: 5
    Last Post: 07-27-2011, 10:21 AM
  5. SQL wildcard character excluding
    By sandlucky in forum Access
    Replies: 2
    Last Post: 03-28-2011, 03:33 AM

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