2017-05-05 48 views
1

我想在Access中製作可搜索的表單。設置將是5-6個文本框,一對夫婦切換和一個按鈕。您將任何信息輸入到文本框中,單擊該按鈕,並且只顯示符合所有條件的記錄。訪問2013通過按鈕應用多個過濾器到表單

Current Form

我發現,似乎給我所有的互聯網上的一些代碼,我將需要:

http://www.allenbrowne.com/ser-62code.html

但是,當我把它,它都沒有返回。到目前爲止,我只能放入一個文本框,以便在浪費時間添加一堆AND之前確保正確無誤。這是我目前所有代碼:

Private Sub SearchAll_Click() 

If Not IsNull(Me.txtCityCounty) Then 
    strWhere = strWhere & "([City/County] Like "" * " & Me.txtCityCounty & " * "")" 

    Me.Filter = strWhere 
    Me.FilterOn = True 

    End If 

End Sub 

如果是有幫助的,「SearchAll」是我的按鈕,「txtCityCounty」的文本框,「市/縣」的字段名。

當我嘗試在我的文本框中輸入文本並單擊我的按鈕時,它不會返回任何內容,並且下面所有嵌入的文本框都消失,就好像它正在過濾一些沒有出現的東西(我可以向你保證,不是這樣,我正在進入「鹽」)。

我錯過了什麼?這個項目有更簡單的方法嗎?

+0

下面是與該代碼我發現對應的數據庫:http://www.allenbrowne.com/ser-62.html –

回答

0

試試這個沒有這些額外的報價

「([市/縣]像 '* 」& Me.txtCityCounty &「 *')」

如果你願意,你甚至可以擺脫IF語句只要使用:

strwhere = NZ( 「([市/縣]像 '* 」& Me.txtCityCounty &「 *')」, 「」)

0

考慮建立一個過濾器串有條件以及使用該方法DoCmd.ApplyFilter

Dim filterString As String 

filterString = "1 = 1"      

If Not IsNull(Me.txtCityCounty) Then 
    filterString = filterString & "([City/County] Like '*" & Me.txtCityCounty & "*')" 
End if 
If Not IsNull(Me.txtAgePopulation) Then 
    filterString = filterString & "([Age/Population] Like '*" & Me.txtAgePopulation & "*')" 
End if 

If Not IsNull(Me.txtServiceType) Then 
    filterString = filterString & "([ServiceType] Like '*" & Me.txtServiceType & "*')" 
End if 

If Not IsNull(Me.txtInsurance) Then 
    filterString = filterString & "([Insurance] Like '*" & Me.txtInsurance & "*')" 
End if 

If Not IsNull(Me.txtProviders) Then 
    filterString = filterString & "([Providers] Like '*" & Me.txtProviders & "*')" 
End if 

DoCmd.ApplyFilter , filterString