按条件组合框排序

时间:2015-04-27 17:45:49

标签: vba combobox access-vba ms-access-2010

我有一个Access 2010表单,它使用组合框打开带有过滤器和排序顺序的报表cboDeliverableReceived(是/否),cboProductType,cboProjectManager和cboSort - 可以选择all或none。我的问题是排序组合框,用户可以排序5-6项。其中一个选择是"收到日期"。我只想要那些日期输入"已收到"要排序的字段(或在空日期之前输入的日期。)

我在行来源中的列表是

ContractTO
Contract Number
ContractorName
Contractor
ProductType
Product Type
TOBeginDate
Task Order Start Date
TOEndDate
Task Order End Date
Received
Date Product Received

报告的VBA是

strField = ""

If CurrentProject.AllForms("fdlgMasterDeliverables").IsLoaded Then
    If Not IsNull(Forms!fdlgMasterDeliverables!cboSort) Then
        Me.Report.GroupLevel(0).ControlSource = Forms!fdlgMasterDeliverables!cboSort.Column(0)    
        strField = Forms!fdlgMasterDeliverables!cboSort.Column(1) 
        If Not IsNull(Forms!fdlgMasterDeliverables!cboDeliverableReceived) Then
            strField = strField & "," & Forms!fdlgMasterDeliverables!cboDeliverableReceived.Column(1)
        End If
    ElseIf Not IsNull(Forms!fdlgMasterDeliverables!cboDeliverableReceived) Then
        strField = "," & Forms!fdlgMasterDeliverables!cboDeliverableReceived.Column(1)
    End If

表单的VBA是

Private Sub cmdSubmit_Click()
On Error GoTo ErrorHandler

    If IsNull(Me.cboProjectManager) And IsNull(Me.cboProductType) And IsNull(Me.cboDeliverableReceived) Then
        DoCmd.OpenReport "rptMasterDeliverables", acViewPreview
    ElseIf IsNull(Me.cboDeliverableReceived) And IsNull(Me.cboProductType) Then
        DoCmd.OpenReport "rptMasterDeliverables", acViewPreview, , "ProjectManager = '" & Me.cboProjectManager & "'"
    ElseIf IsNull(Me.cboDeliverableReceived) And IsNull(Me.cboProjectManager) Then
        DoCmd.OpenReport "rptMasterDeliverables", acViewPreview, , "ProductType = '" & Me.cboProductType & "'"
    ElseIf IsNull(Me.cboProjectManager) And IsNull(Me.cboProductType) Then
        DoCmd.OpenReport "rptMasterDeliverables", acViewPreview, , "DeliverableReceived = '" & Me.cboDeliverableReceived & "'"
    ElseIf IsNull(Me.cboProductType) Then
        DoCmd.OpenReport "rptMasterDeliverables", acViewPreview, , "[ProjectManager]= '" & Me.cboProjectManager & "' And [DeliverableReceived] = '" & Me.cboDeliverableReceived & "'"
    ElseIf IsNull(Me.cboProjectManager) Then
        DoCmd.OpenReport "rptMasterDeliverables", acViewPreview, , "ProductType = '" & Me.cboProductType & "' And [DeliverableReceived] = '" & Me.cboDeliverableReceived & "'"
    ElseIf IsNull(Me.cboDeliverableReceived) Then
        DoCmd.OpenReport "rptMasterDeliverables", acViewPreview, , "ProjectManager = '" & Me.cboProjectManager & "' And [ProductType] = '" & Me.cboProductType & "'"
    Else
        DoCmd.OpenReport "rptMasterDeliverables", acViewPreview, , "ProjectManager = '" & Me.cboProjectManager & "' And [ProductType] = '" & Me.cboProductType & "' And [DeliverableReceived] = '" & Me.cboDeliverableReceived & "'"
    End If

    DoCmd.Close acForm, "fdlgMasterDeliverables"
    errorhandlerexit:
Exit Sub

是否可以将条件添加到行源中的项目,还是可以采用其他方式完成此操作?非常感谢您对此的帮助。

0 个答案:

没有答案