II制作访问数据库。我有一个带有子表单和几个组合框的表单,用作过滤数据。如果表格中有空白字段,则不会显示我对过滤器的编码
Function searchcriteria()
Dim device, vlan As String
Dim task, strciteria As String
If IsNull(Me.cbodevice) Then
device = "[DEVICE NAME] like '*'"
Else
device = "[DEVICE NAME]= '" & Me.cbodevice & "'"
End If
If IsNull(Me.cbovlan) Then
vlan = "[VLAN ID] like '*'"
Else
vlan = "[VLAN ID]= '" & Me.cbovlan & "'"
End If
strcriteria = device & "And" & vlan
task = "select * from L2PORTDETAILS where " & strcriteria
Me.L2PORTDETAILS_subform.Form.RecordSource = task
Me.L2PORTDETAILS_subform.Form.Requery
End Function]
答案 0 :(得分:0)
设置Filter属性可能更简单:
Function SearchCriteria()
' Preset Me!L2PORTDETAILS_subform.Form.RecordSource to:
' "select * from L2PORTDETAILS"
Dim Filter As String
If Not IsNull(Me!cbodevice.Value) Then
Filter = "[DEVICE NAME]= '" & Me!cbodevice.Value & "'"
End If
If Not IsNull(Me!cbovlan.Value) Then
If Filter <> "" Then
Filter = Filter & " And "
End If
Filter = Filter & "[VLAN ID] = '" & Me!cbovlan.Value & "'"
End If
With Me!L2PORTDETAILS_subform.Form
.Filter = Filter
.FilterOn = (Filter <> "")
End With
End Function