Results 1 to 3 of 3
  1. #1
    standonthefloor is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    6

    Need help with filtering a subform (2 part filter)

    I'm putting together an emergency contacts form for my company, and I'm having trouble with an automatic filter I'm trying to add:
    I have a drop down for Department, and a text box for name. For the Department filter, I'm using an afterUpdate action, and for the Name filter, I'm using a onKeyUp action. They both work fine independently, and through a lot of trial and error, I got it to work when you type a name, then select a department, but for the life of me, I cannot get it to work when you select the department first, and then type a name. Any help would be greatly appreciated. Here's the code I'm using:



    Code:
    Private Sub Combo23_AfterUpdate()
    On Error GoTo Proc_Error
    
    Dim departfilter As String
    Dim namefilter As String
    
    departfilter = "[Department]=" & "Combo23"
    namefilter = "[EmpName] LIKE '*" & Trim(Text27.Value) & "*'"
    
    If (Len(Trim(departfilter)) = 0) Or (Len(Trim(namefilter)) = 0) Then
    Me.ECONsf.Form.Filter = departfilter & namefilter
    Else
    Me.ECONsf.Form.Filter = departfilter & " And " & namefilter
    End If
      Me.ECONsf.Form.FilterOn = True
    
    Proc_Exit:
       Exit Sub
    Proc_Error:
       MsgBox "Error " & Err.Number & " in setting subform filter:" & vbCrLf & Err.Description
       Resume Proc_Exit
    End Sub
    
    
     
    Private Sub Text27_KeyUp(KeyCode As Integer, Shift As Integer)
    On Error GoTo Proc_Error
    
    Dim departfilter As String
    Dim namefilter As String
    
    departfilter = "[Department]=" & "Combo23"
    namefilter = "[EmpName] LIKE '*" & Trim(Text27.Value) & "*'"
    
    If (Len(Trim(departfilter)) = 0) Or (Len(Trim(namefilter)) = 0) Then
    Me.ECONsf.Form.Filter = departfilter & namefilter
    Else
    Me.ECONsf.Form.Filter = departfilter & " And " & namefilter
    End If
      Me.ECONsf.Form.FilterOn = True
    
    Proc_Exit:
       Exit Sub
    Proc_Error:
       MsgBox "Error " & Err.Number & " in setting subform filter:" & vbCrLf & Err.Description
       Resume Proc_Exit
    End Sub
    Click image for larger version. 

Name:	Emergency Contacts Form.jpg 
Views:	4 
Size:	104.9 KB 
ID:	37790

  2. #2
    davegri's Avatar
    davegri is offline Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,741
    Code:
    Private Sub Text27_KeyUp(KeyCode As Integer, Shift As Integer)On Error GoTo Proc_Error
    
    Dim departfilter As String
    Dim namefilter As String
    
    departfilter = "[Department]=" & "Combo23"
    namefilter = "[EmpName] LIKE '*" & Trim(Text27.Text) & "*'"
    
    If (Len(Trim(departfilter)) = 0) Or (Len(Trim(namefilter)) = 0) Then
    Me.ECONsf.Form.Filter = departfilter & namefilter
    Else
    Me.ECONsf.Form.Filter = departfilter & " And " & namefilter
    End If
      Me.ECONsf.Form.FilterOn = True
    Try the red.
    Since the cursor is still in the field being typed, the value hasn't been committed. Text has.

  3. #3
    standonthefloor is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Mar 2019
    Posts
    6
    This, plus a few other tweaks got it working. Thanks davegri!

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

Similar Threads

  1. Replies: 7
    Last Post: 12-04-2018, 07:27 AM
  2. Replies: 10
    Last Post: 02-12-2016, 04:42 PM
  3. Replies: 3
    Last Post: 02-23-2015, 11:57 AM
  4. Replies: 9
    Last Post: 07-03-2014, 12:00 PM
  5. Filter based on part of value
    By bikeordie1 in forum Reports
    Replies: 3
    Last Post: 03-01-2013, 08:52 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