Hello,
I have a problem here that I can't quite figure out as I'm no VBA expert. I have setup a search as you type engine on a form and it is currently working but the I cannot type any spaces to search for multiply words. Maybe I have approched this incorrectly from the start but here is my code:
Private Sub txtSearchDescription_Change()
'Search as you type code.
Dim SCriteria As String
'Check if Search Field drop down menu is empty. If empty produce error message and exit sub.
If IsNull(Me!cboSearch) = True Or Me!cboSearch = "" Then
MsgBox ("Please select a Search Field before entering a Search Description.")
cboSearch.SetFocus
Exit Sub
End If
'Check to see if form is in Active or History pubs mode.
If cmdModeSwitch.Tag = "Active Pubs" Then
'Statement to create filter based on Search Field drop down menu and Search Description text box.
SCriteria = "(CFTO.[" & Me!cboSearch & "] LIKE '*" & txtSearchDescription.Text & "*')"
ElseIf cmdModeSwitch.Tag = "Pubs History" Then
'Statement to create filter based on Search Field drop down menu and Search Description text box.
SCriteria = "([CFTO - History].[" & Me!cboSearch & "] LIKE '*" & txtSearchDescription.Text & "*')"
End If
Me.Filter = SCriteria
'Turns filter on.
Me.FilterOn = True
'Statement to place the cursor correctly in the Search Description textbox.
Me.txtSearchDescription.SelStart = Len(Me.txtSearchDescription.Text)
'Statement to remove filter if Search Description textbox is empty.
If Len(txtSearchDescription) = 0 Or IsNull(txtSearchDescription) = True Then
Me!txtSearchDescription.SetFocus
Me.FilterOn = False
End If
Me!txtSearchDescription.SetFocus
End Sub
I know my problem is with this statment "Me.txtSearchDescription.SelStart = Len(Me.txtSearchDescription.Text)" but the search as you type feature will not work without it.
Thanks for help,
I have a problem here that I can't quite figure out as I'm no VBA expert. I have setup a search as you type engine on a form and it is currently working but the I cannot type any spaces to search for multiply words. Maybe I have approched this incorrectly from the start but here is my code:
Private Sub txtSearchDescription_Change()
'Search as you type code.
Dim SCriteria As String
'Check if Search Field drop down menu is empty. If empty produce error message and exit sub.
If IsNull(Me!cboSearch) = True Or Me!cboSearch = "" Then
MsgBox ("Please select a Search Field before entering a Search Description.")
cboSearch.SetFocus
Exit Sub
End If
'Check to see if form is in Active or History pubs mode.
If cmdModeSwitch.Tag = "Active Pubs" Then
'Statement to create filter based on Search Field drop down menu and Search Description text box.
SCriteria = "(CFTO.[" & Me!cboSearch & "] LIKE '*" & txtSearchDescription.Text & "*')"
ElseIf cmdModeSwitch.Tag = "Pubs History" Then
'Statement to create filter based on Search Field drop down menu and Search Description text box.
SCriteria = "([CFTO - History].[" & Me!cboSearch & "] LIKE '*" & txtSearchDescription.Text & "*')"
End If
Me.Filter = SCriteria
'Turns filter on.
Me.FilterOn = True
'Statement to place the cursor correctly in the Search Description textbox.
Me.txtSearchDescription.SelStart = Len(Me.txtSearchDescription.Text)
'Statement to remove filter if Search Description textbox is empty.
If Len(txtSearchDescription) = 0 Or IsNull(txtSearchDescription) = True Then
Me!txtSearchDescription.SetFocus
Me.FilterOn = False
End If
Me!txtSearchDescription.SetFocus
End Sub
I know my problem is with this statment "Me.txtSearchDescription.SelStart = Len(Me.txtSearchDescription.Text)" but the search as you type feature will not work without it.
Thanks for help,