通过查询帮助访问 VBA 循环
我有一个表单(Cobind_frmMain),允许用户创建附加到它的标题池。因此,有一个顶级池名称 (TopLvlPoolName),并且在子表单上,标题将添加到其中。我需要的是为每个标题发布一份报告。我已准备好报告和查询。现在,报告将在一个文件中显示所有标题。标题位于名为“CatCode”的字段中。
我需要的是以下内容:
1. 将每个标题另存为 PDF 并将其保存到我们的服务器。
2. 打开电子邮件并附加 PDF。
3. 重复直到完成所有标题。
编辑:这是我到目前为止的代码,我仍然收到的错误消息是:“设置记录集”行上的“参数太少”。我正在尝试在 strSQL 行中设置参数。我希望 PartPoolName(在 Cobind_qryReport 中,一个查询)等于打开表单上的 TopLvlPoolName。下面列出了 Cobind_qryReport 的 SQL:
Private Sub btn_Run_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
strSQL = "Select * FROM Cobind_qryReport WHERE PartPoolName = " & Me.TopLvlPoolName
Set rs = db.OpenRecordset(strSQL)
On Error GoTo Err_PO_Click
If MsgBox("Do you wish to issue the cobind invites?", vbYesNo + vbQuestion, "Confirmation Required") = vbYes Then
rs.MoveFirst
Do While Recordset.EOF = False
DoCmd.OutputTo acOutputReport, "Cobind_rptMain", acFormatPDF, "K:\OB MS Admin\Postage\CoBind Opportunities\Sent Invites\" & [CatCode] & "_" & [PartPoolName] & "Cobind Invite_" & Format(Now(), "mmddyy") & ".pdf"
DoCmd.SendObject acSendReport, "Cobind_rptMain", acFormatPDF, , , , [CatCode] & "_" & [PartPoolName] & " Cobind Invite", "Please find the cobind invite attached. Response is needed by " & [RSVP] & ". Thank you.", True
Recordset.MoveNext
Loop
End If
Exit_PO_Click:
MsgBox ("It didn't work")
Exit Sub
Err_PO_Click:
MsgBox Err.Description
Resume Exit_PO_Click
End Sub
Cobind_qryReport SQL:
选择 tblEvents.EventTitle、Cobind_tblPartic.CatCode、Cobind_tblPartic.CodeQty、Cobind_tblPartic.PartPoolName、Cobind_tblTopLvl.RSVP、Cobind_tblPartic.ID 从 Cobind_tblTopLvl、Cobind_tblPartic 内部连接 tblEvents ON Cobind_tblPartic.CatCode = tblEvents.EventCode 按 tblEvents.EventTitle、Cobind_tblPartic.CatCode、Cobind_tblPartic.CodeQty、Cobind_tblPartic.PartPoolName、Cobind_tblTopLvl.RSVP、Cobind_tblPartic.ID 分组 按 Cobind_tblPartic.ID 排序;
再次感谢您的所有帮助!
I have a form (Cobind_frmMain) that allows the user to create a pool of titles that are attached to it. So there is a top level Pool Name (TopLvlPoolName) and on a subform, the titles are added to it. What I need is to issue a Report for each of the titles. I have the report and queries all set up. Right now, the report will show all the titles in one file. The titles are in a field called "CatCode".
What I need is the following:
1. Save each title as a PDF and save it to our server.
2. Open email and attach the PDF.
3. Repeat until all titles are done.
EDIT: This is what I have so far for code and the error message I still get is: "Too Few Parameters" on the Set Recordset line. I'm trying to set the parameter in the strSQL line. I want the PartPoolName (in Cobind_qryReport, a query) to equal the TopLvlPoolName on the open form. The SQL for Cobind_qryReport is listed below:
Private Sub btn_Run_Click()
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim strSQL As String
Set db = CurrentDb
strSQL = "Select * FROM Cobind_qryReport WHERE PartPoolName = " & Me.TopLvlPoolName
Set rs = db.OpenRecordset(strSQL)
On Error GoTo Err_PO_Click
If MsgBox("Do you wish to issue the cobind invites?", vbYesNo + vbQuestion, "Confirmation Required") = vbYes Then
rs.MoveFirst
Do While Recordset.EOF = False
DoCmd.OutputTo acOutputReport, "Cobind_rptMain", acFormatPDF, "K:\OB MS Admin\Postage\CoBind Opportunities\Sent Invites\" & [CatCode] & "_" & [PartPoolName] & "Cobind Invite_" & Format(Now(), "mmddyy") & ".pdf"
DoCmd.SendObject acSendReport, "Cobind_rptMain", acFormatPDF, , , , [CatCode] & "_" & [PartPoolName] & " Cobind Invite", "Please find the cobind invite attached. Response is needed by " & [RSVP] & ". Thank you.", True
Recordset.MoveNext
Loop
End If
Exit_PO_Click:
MsgBox ("It didn't work")
Exit Sub
Err_PO_Click:
MsgBox Err.Description
Resume Exit_PO_Click
End Sub
Cobind_qryReport SQL:
SELECT tblEvents.EventTitle, Cobind_tblPartic.CatCode, Cobind_tblPartic.CodeQty, Cobind_tblPartic.PartPoolName, Cobind_tblTopLvl.RSVP, Cobind_tblPartic.ID
FROM Cobind_tblTopLvl, Cobind_tblPartic INNER JOIN tblEvents ON Cobind_tblPartic.CatCode = tblEvents.EventCode
GROUP BY tblEvents.EventTitle, Cobind_tblPartic.CatCode, Cobind_tblPartic.CodeQty, Cobind_tblPartic.PartPoolName, Cobind_tblTopLvl.RSVP, Cobind_tblPartic.ID
ORDER BY Cobind_tblPartic.ID;
Thank you again for all your help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您查询的
Cobind_qryReport
有一个需要设置的参数。如果您想知道参数名称,请尝试以下代码更新
既然您知道您有一个参数在执行
select * from Cobind_qryReport
操作,那么设置该参数然后使用 qdf 打开记录集可能会更容易,例如注意:您可以在设置参数值时序数的位置,
例如
qdf.Parameters("Foo").value = 7832
You're query
Cobind_qryReport
has a parameter that you need to set. if you want to know the parameter name try the following codeUpdate
Since you know you've got a parameter doing
select * from Cobind_qryReport
it might just be easier to set the parameter and then use the qdf to open the recordset e.g.Note: you can use the parameter name in the place of the ordinal when setting the parametervalue
e.g.
qdf.Parameters("Foo").value = 7832