我是昨天刚接触VBA的人。...直到用户需要在没有PC上的电子邮件应用程序的情况下发送电子邮件之前,从未真正进行过编码。在编码的一小部分中,您会看到执行DoCmd命令时会创建报告“ VRRrep222”的PDF,执行该报告时,我必须输入需要创建的“ VRR#”。完成此操作后,将创建并发送电子邮件。在filename =中,PDF的名称将是“ VRRrep222”和今天的日期,但是我需要输入的VRR#来生成报告,同时也是文件名中的数字以及我执行的代码中的主题行不要粘贴在这里。有没有一种方法可以关联被拉出的报告#,以便可以将其添加到PDF名称和主题行而无需手动输入?
Dim filename As String, todaydate As String
Dim Msg As Object
Dim Supplier As String
Supplier = InputBox("Supplier E-mail?")
todaydate = Format(Date, "MMDDYYYY")
filename = Application.CurrentProject.Path & "\VRRrep222_" & todaydate & ".pdf"
DoCmd.OutputTo acReport, "VRRrep222", acFormatPDF, filename, False
Set Msg = CreateObject("CDO.Message")
With Msg
Msg.To = Supplier
Msg.From = ""
Msg.cc = ""
Msg.bcc = ""
Msg.Subject = ""
Msg.TextBody = "This is an automated email that is being sent as an ALERT only. If the disposition is RETURN TO VENDOR, you will be notified with another email."
Msg.addattachment filename
Msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = ""
Msg.Configuration.Fields.Update
Msg.Send
End With
Kill filename
Set Msg = Nothing
End Sub
不要在弹出提示中使用动态参数化查询。使用表格控件输入标准参数。具有查询参数参考表控件或使用OpenReport方法将过滤器应用于报表。然后代码可以引用该控件以构建文件名和主题。
filename = Application.CurrentProject.Path & "\" & Me.tbxVRR & "_" & todaydate & ".pdf"
DoCmd.OpenReport "VRRrep222", acViewPreview, , "YOURfieldname=" & Me.tbxVRR, acHidden
DoCmd.OutputTo acReport, "VRRrep222", acFormatPDF, filename, False
DoCmd.Close acReport, "VRRrep222", acSaveNo
...
.Subject = Me.tbxVRR