我有一个表单,我有3个不同的组合框,我希望能够动态过滤。 ComboBox被称为cboVendor
,cboRegion
,cboPosition
。当我单独过滤ComboBox时,它可以正常工作,但是当我尝试过滤Vendor然后Region然后置位时,子表单仅在我选择的最后一个组合框下拉列表上更新数据,而不是仅限制数据以前选择的组合框。
我能够让每个组合框根据其他框动态更新,我只是不能让子窗体以这种方式显示数据。
以下是每个组合框的单个副本:
Private Sub cboVendor_AfterUpdate()
Dim myVendor As String
myVendor = "Select * from TblVendor where ([Vendor] = '" & Me.cboVendor & "')"
Me.tbl_Vendor_subform1.Form.RecordSource = myVendor
Me.tbl_Vendor_subform1.Form.Requery
Me.cboRegion = Null
Me.cboPosition = Null
Me.cboRegion.Requery
End Sub
Private Sub cboRegion_AfterUpdate()
Dim myRegion As String
myRegion = "Select * from TblVendor where ([Region] = '" & Me.cboRegion & "')"
Me.tbl_Vendor_subform1.Form.RecordSource = myRegion
Me.cboPosition = Null
Me.cboPosition.Requery
End Sub
Private Sub cboPosition_AfterUpdate()
Dim myPosition As String
myPosition = "Select * from TblVendor where ([Position] = '" & Me.cboPosition & "')"
Me.tbl_Vendor_subform1.Form.RecordSource = myPosition
End Sub
答案 0 :(得分:0)
尝试使用此命令。
strDataSource = "Select * from TblVendor where ([Vendor] = '" & Me.cboVendor & "' AND [Region] = '" & _
Me.cboRegion & "' AND [Position] ='" & Me.cboPosition & "')"
Me.tbl_Vendor_subform1.Form.RecordSource = strDataSource
Me.tbl_Vendor_subform1.Form.Requery