我需要使用从组合框中输入或选择的字符串来过滤连续形式。下面是我试图用来捕获过滤器字符串的代码。发生的情况是,当在列表中键入文本时,而不是在后面捕获字符串,而是抛出一个错误,指示组合框为 Null。
我把这个功能放在哪里?我正在考虑将代码添加到 Combobox_Selected 事件中,但这不会使用户能够键入任意关键字来进一步过滤表单的内容。
Private Sub txtUSPSKeySearch_Change()
On Error GoTo Err_txtUSPSKeySearch_Change
Dim searchStr As String
searchStr = txtUSPSKeySearch.Value
If (Not IsNull(searchStr) And Len(searchStr) > 1) Then
Else
' Move the cursor to the end of the combo box.
Me.txtUSPSKeySearch.SetFocus
Me.txtUSPSKeySearch.SelStart = Len(Me.txtUSPSKeySearch.Value)
End If
'Error Handling
Exit_txtUSPSKeySearch_Change:
Exit Sub
Err_txtUSPSKeySearch_Change:
If Err.Number = 5 Then
MsgBox "You must make a selection(s) from the list" _
, , "Selection Required !"
Resume Exit_txtUSPSKeySearch_Change
Else
'Write out the error and exit the sub
MsgBox Err.Description
Resume Exit_txtUSPSKeySearch_Change
End If
End Sub