Results 1 to 5 of 5
  1. #1
    mstevens is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2013
    Posts
    2

    Filtering based on alphabetic buttons then list

    Guys,

    I'm somewhat rusty with VBA but have been put in a spot trying to find a routine(s) that achieve the following on a form

    a) 1st level filter - Alphabetic buttons, 1 each, A-Z

    results filtered by selected alphabetic letter to

    b) A list - then click on list item to sub-select matching items in a given datasheet

    I have not coded yet but thought I would ask first if anyone has such a set of routines I could adapt or is aware of a source?

  2. #2
    maximus's Avatar
    maximus is offline Expert
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Location
    India
    Posts
    931

    Filtering Form

    I have a simple table to demonstrate what I have done:
    Table Name: exp_2
    Fields: ID(Autonumber PK), Employee_Name(Text)

    I have a form RecordSource table exp_2. One the form Header I have a multi-select list box with alphabet buttons A-Z. When I click on one of the alphabet buttons e.g. "A" all Employee's name starting with the Alphabet "A" is displayed in the List box. The code attached to Alphabet button A as follows:

    Code:
    Private Sub Command0_Click()
    'The Name of the Listbox is List13
    Dim strSQL As String
    strSQL = "SELECT Employee_Name FROM exp_2 WHERE exp_2.Employee_Name Like 'a*'"
    Me.List13.RowSource = strSQL
    Me.List13.Requery
    End Sub
    Now I will select the names from the List Box based on which I want to filter my form and then Click Filter button. Then I use the code attached to the filter button to loop through the options selected in the list box to generate the filter criteria and filter the form. The code attached to filter button:

    Code:
    Private Sub Command12_Click()
    Dim ctlList As Control, varItem As Variant, strCriteria As String
     
     'Return Control object variable pointing to list box.
     Set ctlList = Me.List13
     'Loop through selected items.
     For Each varItem In ctlList.ItemsSelected
     If Not IsNull(ctlList.ItemData(varItem)) Then
        
        If Len(strCriteria) > 0 Then
            
            strCriteria = strCriteria & " Or Employee_Name='" & ctlList.ItemData(varItem) & "'"
        Else
            strCriteria = "Employee_Name='" & ctlList.ItemData(varItem) & "'"
        End If
            
    End If
     Next varItem
     If Len(strCriteria) > 0 Then
            Me.Filter = strCriteria
        Me.FilterOn = True
    Else
        MsgBox "Please Select Names from drop down "
    End If
    strCriteria = ""
    End Sub
    To Remove Filter Create a Command button and attach this Code to its OnClick Even:
    Me.FilterOn = False

  3. #3
    libraccess's Avatar
    libraccess is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    Mar 2012
    Location
    Napier New Zealand
    Posts
    129
    this is one I've saved for future use. In fact very good future use

  4. #4
    mstevens is offline Novice
    Windows XP Access 2003
    Join Date
    Feb 2013
    Posts
    2
    Quote Originally Posted by maximus View Post
    I have a simple table to demonstrate what I have done:
    Maximus, this is just the job and thank you for helping me out of a hole (with minimal, codeless, info from me for which I apologise).

    Thanks again - this solution will be put to very good use....

  5. #5
    maximus's Avatar
    maximus is offline Expert
    Windows 7 64bit Access 2010 64bit
    Join Date
    Aug 2009
    Location
    India
    Posts
    931
    Please mark the Thread Solved this will help others searching for the same solution.

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

Similar Threads

  1. Filtering by buttons
    By adrisoares in forum Forms
    Replies: 5
    Last Post: 01-01-2013, 09:21 PM
  2. list form filtering from 1 combo box
    By cooper in forum Forms
    Replies: 5
    Last Post: 08-18-2011, 05:32 PM
  3. Replies: 1
    Last Post: 01-28-2011, 07:59 PM
  4. Creating Sort Buttons in a Header in a list view
    By marttaaayyy!! in forum Programming
    Replies: 4
    Last Post: 03-29-2010, 11:08 AM
  5. Count numerical and alphabetic fields
    By nukethrower in forum Queries
    Replies: 0
    Last Post: 02-26-2008, 10:51 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