Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql MS Access筛选器窗体打开特定记录的报告_Sql_Ms Access_Vba - Fatal编程技术网

Sql MS Access筛选器窗体打开特定记录的报告

Sql MS Access筛选器窗体打开特定记录的报告,sql,ms-access,vba,Sql,Ms Access,Vba,我正在尝试创建一个表单ReportSearch,它有多个组合框和文本框,允许用户缩小报告上显示的结果范围。并非所有字段都必须用于搜索 单击后,以下代码将要求输入所用特定ID的参数值。如果我只单击OK而不在MsgBox中输入任何内容,则报告将被打开,没有任何记录 Private Sub cmdFilter_Click() Dim strWhere As String Dim lngLen As Long Const conJetDate = "\#mm\/dd\/yy\#" If Not Is

我正在尝试创建一个表单ReportSearch,它有多个组合框和文本框,允许用户缩小报告上显示的结果范围。并非所有字段都必须用于搜索

单击后,以下代码将要求输入所用特定ID的参数值。如果我只单击OK而不在MsgBox中输入任何内容,则报告将被打开,没有任何记录

Private Sub cmdFilter_Click()
Dim strWhere As String
Dim lngLen As Long

Const conJetDate = "\#mm\/dd\/yy\#"

If Not IsNull(Me.cboSearchJob) Then
   strWhere = strWhere & "(Job.id = " & Me.cboSearchJob & ") AND "
End If

If Not IsNull(Me.cboSearchEmployee) Then
   strWhere = strWhere & "(Employee.ID = " & Me.cboSearchEmployee & ") AND "
End If

If Not IsNull(Me.cboSearchService) Then
   strWhere = strWhere & "(Service.ID = " & Me.cboSearchService & ") AND "
End If

If Not IsNull(Me.tboStartDate) Then
    strWhere = strWhere & "(DateWorked >= " & Format(Me.tboStartDate, conJetDate) & ") AND "
End If
If Not IsNull(Me.tboEndDate) Then
   strWhere = strWhere & "(DateWorked < " & Format(Me.tboEndDate + 1, conJetDate) & ") AND "
End If

lngLen = Len(strWhere) - 5
If lngLen <= 0 Then
   MsgBox "No Results", vbInformation, "No Search Available."
Else
    strWhere = Left$(strWhere, lngLen)

    DoCmd.OpenReport "JobReport", acViewPreview
    Reports!JobReport.Filter = strWhere
    Reports!JobReport.FilterOn = True

   End If


End Sub
在这一点上,我完全不知所措

很明显,我在这里遗漏了一些东西。让我知道我需要以何种方式修改此代码,以使其打开我的报表JobReport根据我的表单ReportSearch进行筛选


谢谢

报表不像表单那样是动态的,打开后无法对其进行过滤。当报表在打印预览中打开时,它读取数据,进行布局和格式设置,然后它完全是静态的

要打开包含过滤数据的报表,请使用
DoCmd.OpenReport
WhereCondition
参数:

DoCmd.OpenReport "JobReport", acViewPreview, WhereCondition:=strWhere

你说得对,那东西不见了。现在,我在查询表达式(Service.ID=3)中收到错误3075“Missing”)、或项(我使用If Not IsNull(Me.cboSearchService),然后使用strWhere=“(Service.ID=“&Me.cboSearchService&”)和“End If@Stephenson:注释中的代码在此处漏掉一个空格:
)和“代码/ >,但在问题上是正确的。如果空白被删除,删除最后5个字符将关闭。这很好。我所有的组合框都会用来过滤报告,但是我的日期文本框什么都不做。”史蒂芬森:“你可能需要<代码>”\“mm\/dd\yyyy\”“<代码>而不是<代码>”\m\m\/dd/yy\y]。“
(4位数字年份)。——原问题已回答,请接受答案,将问题标记为已解决。
DoCmd.OpenReport "JobReport", acViewPreview, WhereCondition:=strWhere