我在窗體中有多個組合框(acct_nbr,type,team_aud)。我正在尋找一種基於每個組合框的選擇過濾子表單(作爲數據表)的方法。如果組合框未在過濾器中使用,則子窗體數據僅在另外兩個組合框上進行過濾。如何過濾表單中帶有多個組合框的Access子表單?
這是我到目前爲止有:
Private Sub cboAccountFilter_AfterUpdate()
Call FilterSubform
End Sub
Private Sub cboTypeFilter_AfterUpdate()
Call FilterSubform
End Sub
Private Sub txtTeamAuditorFilter_AfterUpdate()
Call FilterSubform
End Sub
Private Sub FilterSubform()
Dim strWhere As String
If Nz(Me.cboAccountFilter, "") <> "" Then
strWhere = strWhere & "[acct_nbr] = '" & Me.cboAccountFilter & " ' AND "
End If
If Nz(Me.cboTypeFilter, "") <> "" Then
strWhere = strWhere & "[Type] = '" & Me.cboTypeFilter & " ' AND "
End If
If Nz(Me.txtTeamAuditorFilter, "") <> "" Then
strWhere = strWhere & "[team_aud] = '" & Me.txtTeamAuditorFilter & " ' AND "
End If
If strWhere <> "" Then
strWhere = Left(strWhere, Len(strWhere) - 5)
Me.fsubStatsDashPrimarySix.Form.Filter = strWhere
Me.fsubStatsDashPrimarySix.Form.FilterOn = True
Else
Me.fsubStatsDashPrimarySix.Form.Filter = ""
Me.fsubStatsDashPrimarySix.Form.FilterOn = False
End If
End Sub
當我點擊的組合框一個我沒有收到錯誤,但所有的數據被過濾掉。
請正確格式化源代碼。 –
當您在每個單引號之前消除空格時會發生什麼? - >'「'AND''(即將它們更改爲'」'AND「'」) – HansUp
當您將'strWhere'字符串分配給'Filter'時,您應該明智地檢查它。在「立即」窗口中添加'Debug.Print strWhere',運行代碼並查看其輸出。 (Ctrl + g會帶你到那裏。) – HansUp