Microsoft Access-使用多个组合框来设置报告

时间:2018-08-21 05:50:27

标签: ms-access

好的,我缺乏VBA专业知识。我想使用5个组合框和2个文本框作为参数来查找并基于这些选择生成报告。它提取所有适用数据库条目的信息,并将它们放入我单击命令按钮时生成的报告中。我有2个文本框设置,它们是从另一个站点提取的截止日期和日期框。基本上,我希望能够使用此现有代码并为所有其他组合框添加信息。如果有可能,请告诉我。我附上了附件,以尝试对此加以澄清。

页面设置和简要说明:

Private Sub Submit_Click()

On Error GoTo Err_Handler      'Remove the single quote from start of this line once you have it working.
'Purpose:       Filter a report to a date range.
'Documentation: http://allenbrowne.com/casu-08.html
'Note:          Filter uses "less than the next day" in case the field has a time component.
Dim strReport As String
Dim strDateField As String
Dim strWhere As String
Dim lngView As Long
Const strcJetDate = "\#mm\/dd\/yyyy\#"  'Do NOT change it to match your local settings.

'DO set the values in the next 3 lines.
strReport = "Search"            'Put your report name in these quotes.
strDateField = "[Date]"         'Put your field name in the square brackets in these quotes.
lngView = acViewReport          'Use acViewNormal to print instead of preview.

'Build the filter string.
If IsDate(Me.startdate) Then
    strWhere = "(" & strDateField & " >= " & Format(Me.startdate, strcJetDate) & ")"
End If
If IsDate(Me.enddate) Then
    If strWhere <> vbNullString Then
        strWhere = strWhere & " AND "
    End If
    strWhere = strWhere & "(" & strDateField & " < " & Format(Me.enddate + 1, strcJetDate) & ")"
End If

'Close the report if already open: otherwise it won't filter properly.
If CurrentProject.AllReports(strReport).IsLoaded Then
    DoCmd.Close acReport, strReport
End If
'Open the report.
Debug.Print strWhere        'Remove the single quote from the start of this line for debugging purposes.
DoCmd.OpenReport strReport, lngView, , strWhere

Exit_Handler:
Exit Sub

Err_Handler:
If Err.Number <> 2501 Then
    MsgBox "Error " & Err.Number & ": " & Err.Description, vbExclamation, "Cannot open report"
End If
Resume Exit_Handler

End Sub

0 个答案:

没有答案