[免责声明:我是自学成才的新手!]
我有一个FORM,QUERY从中获取数据并使用它来填充REPORT。当最终用户完成报告并单击按钮时,应该发生以下情况:
1)FORM将所有数据保存在TABLE上的新记录中 2)查询通过FORM中的ID(自动编号)拉取该记录 3)QUERY使用TABLE中的数据填充REPORT 4)FORM和QUERY关闭 - 无需保存。
QUERY使用以下条件从相应的TABLE中提取所有数据:[Forms]![Data_Input_Form]![ID]
但是,我的报告空白了!伊克!
我有一个类似的QUERY,它从同一个TABLE中提取数据并使用以下条件将其填充到类似的REPORT:Like Nz([Forms]![Home_Form]![Incident_ID_Lookup_text],“*”)
不出所料,当我将这个添加到QUERY中时,我想要它的工作方式无效,它报告了所有以前的记录。
'------------------------------------------------------------
' Add Report [and Open Report] Button Click
'
'
'------------------------------------------------------------
Private Sub Add_Rpt_Btn_Click()
If MsgBox("Are you sure? No backsies.", vbYesNo, "Add Report?") = vbNo Then
Exit Sub
End If
'Check for Necessary Fields and Add New Record
If (IsNull(Me.Person_Filing) Or IsNull(Me.Nature_Lst) Or IsNull(Me.Location_Cmb) Or IsNull(Me.Summary) Or IsNull(Me.Narrative)) = True Then
MsgBox "Looks like you left some important information out. Please fill out all fields with an asterisk.", vbOKOnly, Whoops
Exit Sub
Else
DoCmd.GoToRecord , , acNewRec
End If
'Run Query to Open Report
DoCmd.OpenQuery "Form_to_Report_Qry"
DoCmd.OpenReport "Incident_Report_1", acViewReport, , [ID] = [Forms]![Data_Input_Form]![ID]
'Close Query without Saving
DoCmd.Close acQuery, "Form_to_Report_Qry", acSaveNo
'Close Form without Saving
DoCmd.Close acForm, "Data_Input_Form", acSaveNo
End Sub
REPORT需要填充最新的记录,但它一直是空白。
那是因为你移动一个新的(空)记录 - 没有ID。
我想,你只需要使用表单的当前ID - 并使用正确的语法过滤器:
Private Sub Add_Rpt_Btn_Click()
If MsgBox("Are you sure? No backsies.", vbYesNo, "Add Report?") = vbNo Then
Exit Sub
End If
' Check for Necessary Fields and Add New Record
If (IsNull(Me.Person_Filing) Or IsNull(Me.Nature_Lst) Or IsNull(Me.Location_Cmb) Or IsNull(Me.Summary) Or IsNull(Me.Narrative)) = True Then
MsgBox "Looks like you left some important information out. Please fill out all fields with an asterisk.", vbOKOnly, Whoops
Exit Sub
End If
' If not saved, save the current record.
If Me.Dirty = True Then
Me.Dirty = False
End If
DoCmd.OpenReport "Incident_Report_1", acViewReport, , "[ID] = " & Me![ID].Value & ""
' Close Form without Saving
DoCmd.Close acForm, Me.Name, acSaveNo
End Sub