我正在使用Microsoft Access。我有一个SQL查询。 Select * from people
我有当前代码连接到表单按钮。我如何修复我的代码以正确生成报告?
DoCmd.OpenQuery "PeopleSearch", acViewPreview 'open query
DoCmd.SelectObject acQuery, "PeopleSearch"
RunCommand acGenerateReport
答案 0 :(得分:2)
你真的很亲密。这是一个如何完成的例子。此外,我在报告生成结束时关闭了查询。
Private Sub Command24_Click()
On Error GoTo Err_Command24_Click
DoCmd.OpenQuery "PeopleSearch", acViewPreview
DoCmd.SelectObject acQuery, "PeopleSearch"
RunCommand acCmdNewObjectAutoReport
DoCmd.Close acQuery, "PeopleSearch"
Exit_Command24_Click:
Exit Sub
Err_Command24_Click:
MsgBox Err.Description
Resume Exit_Command24_Click
End Sub