注意:我对 VBA 很陌生。我正在尝试为我们的自定义过滤器创建一个或功能,用户可以选择过滤一个或另一个。我认为用户需要选择所有三个字段、比较和标准以使其成为一个选择,然后当按下或按钮时将生成另一个选择,依此类推......直到单击过滤器按钮。我有过滤器上的代码,到目前为止它确实有效。
这只是我迄今为止拥有的一个愚蠢的草稿 Private Sub cmdOr_Click()
Dim selectOr As Integer
这里我不确定如何将这三个字段设置为一个指标
selectOr = Field & Comparison & Criteria
If IsNull(selectOr) Then
MsgBox "All three fields, Comparison and Criteria must be selected", vbOKCancel, "Filter"
Else
在这里我想增加我的
selectOr
,以便用户可以选择尽可能多的Or
选项
selectOr 1
End Sub
我希望我很清楚,如果没有,请告诉我!谢谢!
到目前为止,这是我的过滤器按钮中的内容。注意:还有词典、收藏等模块用到。
Private Sub cmdOK_Click()
Dim Filter As IFilter, filterString As String, filterComparison As String, FilterCriteria As String, sanitizedFilterCriteria As
String, PrimaryFilter As String, primarySchema As String,
primaryTable As String, primaryKey As String, targetTable As String,
targetField As String, Target() As String, filterItem As
ControlDefinition_Filter
Me.Dirty = False
'Gather data for the primary filter from the active form
With XFormToFilter
.ResetFilter
Set .FilterBuilder.FormToFilter = FormToFilter
PrimaryFilter = IIf(.BaseFilter = vbNullString, _
.NullFilter, _
.BaseFilter)
primaryTable = .FilterTable
primaryKey = .key
End With
With Me.RecordsetClone
If .RecordCount > 0 Then
.MoveFirst
Do While Not .EOF
'Get the schema, table/view, and control targetted by the filter
Target = Split(.fields("Field").Value, ".")
targetTable = IIf(Left(Target(0), 6) = "SELECT", GetTableName(Target(0)), Target(0))
targetField = Target(1)
filterComparison = Nz(.fields("Comparison").Value, vbNullString)
FilterCriteria = Nz(.fields("Criteria").Value, vbNullString)
Set filterItem = filterDict.item(.fields("Field").Value)
If filterItem.HasCriteria Then 'Get the stored equivalent for the criterion if available
sanitizedFilterCriteria = filterItem.GetCriteriaValue(FilterCriteria)
If sanitizedFilterCriteria <> vbNullString Then _
FilterCriteria = sanitizedFilterCriteria
End If
filterString = _
CreateFilterString(.fields("FieldType"), targetField, targetTable, _
filterComparison, FilterCriteria)
filterString = FilterRegExp(filterString)
If Filter Is Nothing Then
Set Filter = XFormToFilter.FilterBuilder
Filter.SetPrimaryFilter PrimaryFilter, primaryTable, primaryKey
End If
Filter.AddSubFilter "Filter" & .fields("ID"), _
filterString, targetTable, subformDict(targetTable)
.MoveNext
Loop
End If
End With
If Not Filter Is Nothing Then
Dim finalFilter As String
Filter.OpenFilteredRecordset
XFormToFilter.SetFoundRecords
DoCmd.Close acForm, "Filter_Create_popup", acSaveNo
End If
'error handling is here
End Sub`