0
在Access 2010中,我試圖爲表格上的聯繫人表創建一個搜索框。我一直在得到一個錯誤13類型不匹配錯誤,我怎樣才能得出它?
這裏是我的代碼:
Private Sub Command119_Click()
On Error GoTo Command119_Click_Err
If (Eval("[Forms]![frmTitlePage]![SearchBox] Is Null")) Then
' Clear Filter when search box empty
DoCmd.RunCommand acCmdRemoveFilterSort
End If
' Handle "'s in search
TempVars.Add "strSearch", Replace(Forms!frmTitlePage!SearchBox, """", """""")
' Build the Filter
TempVars.Add "strFilter", "([Last Name] Like "" * " & [TempVars]![strSearch] & " * "")"
TempVars.Add "strFilter", TempVars!strFilter & " OR ([First Name] Like "" * " & [TempVars]![strSearch] & " * "")"
DoCmd.ApplyFilter "", TempVars!strFilter, ""
TempVars.Remove "strFilter"
TempVars.Remove "strSearch"
Command119_Click_Exit:
Exit Sub
Command119_Click_Err:
MsgBox Error$
Resume Command119_Click_Exit
End Sub
我顯然太可怕了,在這個編碼,因此任何額外的幫助來清理這個搜索工具將高達極大幫助。
你爲什麼要評估表單控件?我認爲你會遇到單引號(D'Arcy)名字的問題。你應該考慮你的表單的過濾器屬性,而不是'DoCmd.RunCommand acCmdRemoveFilterSort' ...開始:) – Fionnuala
什麼是TempVars,它來自哪裏? – Fionnuala
我使用了訪問聯繫人模板中的代碼,並試圖將其模製到我的搜索框中。我怎麼能使用你建議的DoCmd.RunCommandacCmdRemoveFilterSort? – user1496497