1
我有一個要求,使用輸入或從組合框中選擇的字符串過濾連續形式。下面是我試圖用來捕獲過濾器字符串的代碼。會發生什麼情況是,當文本被輸入到列表中而不是在後面被捕獲的字符串中時,反而會拋出錯誤,指示組合框是空的。MS訪問過濾器連續形式
我在哪裏可以放置此功能?我正在考慮將代碼添加到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