ms-access - Microsoft 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
解决方案
推荐阅读
- python - 使用 Python 列表和数组
- powershell - 访问与服务帐户共享的 Google 表格文件会产生 403 禁止错误
- android - Realm Android:在数据模型类中添加领域对象作为子数组
- android - AIR / Android:在清单中添加资产和引用
- webpack - 如何删除 webpack 插件中的条目?
- symfony - JMS Serializer 无法在 Symfony 4 上设置上下文目标属性
- javascript - 手风琴菜单子菜单覆盖菜单而不是扩展它
- c# - 这是交换字节顺序的合法方式吗?
- ios - 如何使 UICollectionView 仅在触摸而不是触摸时选择一个单元格
- c# - 将 Func 列表作为单个 Func 返回