Results 1 to 3 of 3
  1. #1
    fargus47 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    2

    How to Filter Form with Option Group linked to Combo Box

    Hi,



    I am trying to filter a form utilizing an option group that filters the results of an unbound combo box in the form's header (the combo box assists the user in quickly locating a name). I've tried many variations of a Select Case Statement I found on a forum and just keep getting more confused. Thank you in advance for any help you can offer!



    Code:
    Private Sub fraAdmitStatusOptionGroup_AfterUpdate()
    ' filters residents' records in combo box based on selection in option group box
    
    
        Dim strCriteria As String
        Dim strSQL As String
     
        
        Select Case Me!fraAdmitStatusOptionGroup
            'Me! refers to frame/option group name
    
    
            Case "Active"
                ' Option button Active = 1
                 strCriteria = "Active"
    '
            Case "Bed Hold"
                ' Option button Bed Hold =2
                strCriteria = "Bed Hold"
    '
            Case "Expired"
                ' option button Expired =3
                strCriteria = "Expired"
    '
            Case "Discharged"
                ' option button Discharged = 4
                strCriteria = "Discharged"
    '
            Case "LOA"
                ' option button LOA (leave of absence) = 5
                strCriteria = "LOA"
    '
            Case "Potential"
                ' option button Potential = 6
                strCriteria = "Potential"
    '
        End Select
        
            strSQL = "SELECT [tbl_Clinical_Residents].Resident_ID, [tbl_Clinical_Residents].Last_Name, " & _
                    "[tbl_Clinical_Residents].First_Name, [tbl_Clinical_Residents].Admission_Number, " & _
                    "[tbl_Clinical_Residents].Admit_StatusID, FROM tbl_Clinical_Residents WHERE " & _
                    "[tbl_Clinical_Residents].Admit_StatusID = '" & strCriteria & "';"
            Debug.Print strSQL
            
    
    
    '    'Sets combo box row source equal to SQL select statement
        Me!cboSearchByLastName.RowSource = strSQL
    End Sub

  2. #2
    Bob Fitz's Avatar
    Bob Fitz is offline Access Developer
    Windows XP Access 2003
    Join Date
    May 2011
    Location
    Essex UK
    Posts
    3,544
    Perhaps this will work:
    Code:
    Select Case Me!fraAdmitStatusOptionGroup
            'Me! refers to frame/option group name
    
    
            Case 1
                ' Option button Active = 1
                 strCriteria = "Active"
    '
            Case 2
                ' Option button Bed Hold =2
                strCriteria = "Bed Hold"
    '
            Case 3
                ' option button Expired =3
                strCriteria = "Expired"
    '
            Case 4
                ' option button Discharged = 4
                strCriteria = "Discharged"
    '
            Case 5
                ' option button LOA (leave of absence) = 5
                strCriteria = "LOA"
    '
            Case 6
                ' option button Potential = 6
                strCriteria = "Potential"
    '
        End Select
        
            strSQL = "SELECT [tbl_Clinical_Residents].Resident_ID, [tbl_Clinical_Residents].Last_Name, " & _
                    "[tbl_Clinical_Residents].First_Name, [tbl_Clinical_Residents].Admission_Number, " & _
                    "[tbl_Clinical_Residents].Admit_StatusID, FROM tbl_Clinical_Residents WHERE " & _
                    "[tbl_Clinical_Residents].Admit_StatusID = '" & strCriteria & "';"
            Debug.Print strSQL
            
    
    
    '    'Sets combo box row source equal to SQL select statement
        Me!cboSearchByLastName.RowSource = strSQL
    End Sub
    If this helped, please click the star at the bottom left of this posting and add to my reputation . Many thanks.
    Bob Fitzpatrick

  3. #3
    fargus47 is offline Novice
    Windows Vista Access 2010 64bit
    Join Date
    Feb 2013
    Posts
    2
    Hi Bob,

    Thank you for the quick response! When I the code, I'm still getting an error "The SELECT statement includes a reserved word or an argument that is misspelled or missing, or the punctuation is incorrect". Any ideas?

    Thanks!

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

Similar Threads

  1. Replies: 5
    Last Post: 12-19-2011, 02:53 PM
  2. Replies: 5
    Last Post: 11-21-2011, 09:59 PM
  3. Use Option Group to Filter Combo Box Values
    By dgj32784 in forum Programming
    Replies: 2
    Last Post: 06-06-2011, 12:04 PM
  4. Replies: 1
    Last Post: 11-23-2010, 01:30 PM
  5. Combo Box and Option Group Values
    By Desstro in forum Queries
    Replies: 8
    Last Post: 09-06-2010, 11:40 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