Combo box selection disrupting search box functionality (1 Viewer)

vent

Registered User.
Local time
Today, 02:43
Joined
May 5, 2017
Messages
160
Hello everyone

I have a datasheet in split form view. I've added some functionality to it by including a search bar that filters the datasheet based on whatever the user types in. As well as two combo boxes that filter the datasheet based on whatever the user selects. Everything works fine and dandy except for one small thing. Whenever the user makes a selection in either combo box, the functionality of the search box disappears. Here's the VBA for each search option

For the search bar:
Code:
Private Sub SrchText_AfterUpdate()
Me.SrchText.Requery
End Sub

Private Sub txtSearch_Change()
'Create a string (text) variable
    Dim vSearchString As String
    vSearchString = txtSearch.Text
    SrchText.Value = vSearchString
    If Len(Me.SrchText) <> 0 And InStr(Len(SrchText), SrchText, " ", vbTextCompare) Then
        Exit Sub
        End If
    'Me.SearchResults = Me.SearchResults.ItemData(1)
    'Me.SearchResults.SetFocus
    DoCmd.Requery
    Me.txtSearch.SetFocus
    If Not IsNull(Len(Me.txtSearch)) Then
        Me.txtSearch.SelStart = Len(Me.txtSearch)
        End If
End Sub

First combo box:
Code:
Private Sub ComboWSIB_AfterUpdate()
Select Case Me.ComboWSIB.Value
Case "All"
        Me.FilterOn = False        
Case Else
      'filter all values where ComboWSIB value is in WSIB Employer Declaration Complete? field string
       Me.Filter = "InStr([WSIB Employer Declaration Complete?],""" & Me.ComboWSIB.Value & """)>0"
       ' Debug.Print Me.Filter
        Me.FilterOn = True
End Select

Second combo box:
Code:
Private Sub CboPrograms_AfterUpdate()
Select Case Me.CboPrograms.Value
Case "All"
        Me.FilterOn = False        
Case Else
      'filter all values where cboFilter value is in Complete field string
       Me.Filter = "InStr([Program(s)],""" & Me.CboPrograms.Value & """)>0"
       ' Debug.Print Me.Filter
        Me.FilterOn = True
End Select
End Sub

And this is the reset button vba:
Code:
Private Sub cmdReset_Click()
Me.txtSearch = ""
    Me.SrchText = ""
    Me.txtSearch.SetFocus
    DoCmd.Requery
End Sub



If i type something in, nothing happens. Does anyone know why this is? Thank you!

PS Thank you Ridders for helping with the combo box vba
 

shafara7

Registered User.
Local time
Today, 08:43
Joined
May 8, 2017
Messages
118
Maybe you can add..

ComboWSIB.value = 0
CboPrograms.value = 0

..at the end of your searchbox code. So that when you started typing in the searchbox, the filter in the combobox will be reseted.
 

isladogs

MVP / VIP
Local time
Today, 07:43
Joined
Jan 14, 2017
Messages
18,218
Hi Rob

I haven't studied your latest code thoroughly.

However, two things:
1. The code for ComboWSIB_AfterUpdate that I provided was a 'special' case to manage a rather unusual situation

I wouldn't expect you to use the same style of code for the CboPrograms_AfterUpdate event

2. I still strongly recommend you change your field "WSIB Employer Declaration Complete?" from text to boolean.
This will save you a lot of stress in the future

Suggest you upload the relevant part of your db so someone can review your search code properly
 

Users who are viewing this thread

Top Bottom