Microsoft Access向客户端发送电子邮件并从数据库

时间:2016-06-28 09:29:22

标签: database forms email object ms-access

Gday all,

我正在尝试从Microsoft Access向客户端发送报告。

所以我有一个客户表,其中包含客户详细信息,包括电子邮件地址等。

在我的表单中,我使用链接到宏的按钮创建报告并使用“EMailDatabaseObject”通过电子邮件发送 但是这样我无法从我的客户端部分的列表中选择电子邮件地址,我必须在宏构建器中键入一个,或者留空并得到提示。

无论如何我可以将一个Select Query链接到EMailDatabaseObject的“to”部分吗?

或者我还有其他方法可以尝试这样做吗?

2 个答案:

答案 0 :(得分:0)

最好的方法是在VBA中,您可以将报表创建宏转换为VBA代码,并在生成的代码之后添加它

Dim vRecipient As String
Dim vMsg As String
Dim vSubject As String

vMsg = " Your Message here... "
vSubject = " Your Subject here... "
vRecipient = "x@x.xxx" 'probably it is best to select from some listbox 


DoCmd.SendObject acSendReport, " rptYourReport ", acFormatPDF, vRecipient, , , vSubject, vMsg, False

您还可以看到here

答案 1 :(得分:0)

看看这个:

Public Sub cmdTerms_Click()

Dim objOutlook As New Outlook.Application
Dim objMail As MailItem
Dim KnownAs As String
Dim Eml As String
Dim Text As String
Dim PathName As String
Dim PathName2 As String
Dim Quest As Integer
Dim rs As DAO.Recordset

DoCmd.TransferText acExportMerge, "", "qryTerms", conAddrPth & "\DataSource.txt", True, "", 1252

Me.DocName = conAddrPth& “\ DBS服务协议.docm” OpenWordDoc

KnownAs = DLookup("Fname", "qryTerms")
Eml = DLookup("Email", "qryTerms")
Text = "Dear " & KnownAs & vbCr & vbCr & "I'd be grateful if you would read the attached Code of Practice and " & _
   "Service Level Agreement." & vbCr & vbCr & _
   "If you are happy with these terms please complete, sign and return pages one and " & _
   "two of the attachment. " & vbCr & vbCr & "Please let me know if you have any questions or concerns." & vbCr & vbCr & _
   "With best wishes." & vbCr & vbCr & EmailSig

PathName = conAddrPth & "\DBS Service Agreement.pdf"

Set objOutlook = New Outlook.Application
Set objMail = objOutlook.CreateItem(olMailItem)

With objMail
.To = Eml
.Subject = "DBS Checking Service"
.Body = Text
.NoAging = True
.Attachments.Add PathName
.Display (True)
End With

Set objMail = Nothing
Set objOutlook = Nothing

End Sub

这是我使用的东西。以上是您表格上的程序。表单将包含诸如地址等数据。我将使用Word Mail Merge来生成报告(或信函)。如有必要,发送报告也同样容易。