Public Sub prcApplyFiltersFromHeaderControls(frm As Form)
Dim strFilter As String
Dim ctl As Control
' フォームヘッダのコントロールをループ処理
For Each ctl In frm.Section(acHeader).Controls
Select Case True
Case TypeOf ctl Is TextBox
If ctl.Value <> "" Then
If strFilter <> "" Then strFilter = strFilter & " AND "
strFilter = strFilter & "[" & ctl.Tag & "] LIKE '*" & ctl.Value & "*'"
End If
Case TypeOf ctl Is ComboBox
If Not IsNull(ctl.Value) And ctl.Value <> "" Then
If strFilter <> "" Then strFilter = strFilter & " AND "
strFilter = strFilter & "[" & ctl.Tag & "] = '" & ctl.Value & "'"
End If
Case TypeOf ctl Is CheckBox
If ctl.Value = True Or ctl.Value = False Then
If strFilter <> "" Then strFilter = strFilter & " AND "
strFilter = strFilter & "[" & ctl.Tag & "] = " & ctl.Value
End If
End Select
Next ctl
' 構築したフィルタ文字列を適用
If strFilter <> "" Then
frm.Filter = strFilter
frm.FilterOn = True
Else
' すべてのフィルタをクリア
frm.FilterOn = False
End If
End Sub
コメント