如何从MS Access Form发送邮件

时间:2012-10-05 07:29:42

标签: email ms-access

如何从MS Access Form发送邮件。 ?

假设我有一个带有DashBoard表格的MS Access应用程序。 我已将邮件发送到某个邮件地址 比如点击“发送通知按钮”发送通知邮件 如何在MS访问中使用codebuilder

2 个答案:

答案 0 :(得分:2)

我发现您可以使用此代码段发送邮件

Private Sub send_mail()

   Dim olApp As Object
   Dim objMail As Object

   On Error Resume Next 'Keep going if there is an error
   Set olApp = GetObject(, "Outlook.Application") 'See if Outlook is open

    If Err Then 'Outlook is not open
       Set olApp = CreateObject("Outlook.Application") 'Create a new instance 
    End If
  'Create e-mail item
   Set objMail = olApp.CreateItem(olMailItem)

   With objMail
   'Set body format to HTML
     .BodyFormat = olFormatHTML
     .To = "abc@yourmailaddress.com"
     .Cc ="ccaddress@yourmailaddress.com"
     .Subject = "Subject LIne"
     .HTMLBody = "<htmltags>Body Content</htmltags>"
     .send
   End With

  MsgBox "Operation completed successfully"

 End Sub

来源:Thread from Access Programmer site

答案 1 :(得分:0)

我找到了一些基于我用来从联系人主页打开浏览器的代码的电子邮件代码,工作得很好,让我更容易理解。要打开网页,请删除“”mailto:“&amp; ”。

Private Sub cmdEmailContact_Click()
Dim sWebPath As String
Dim sFullLinkPath As String

If IsNull(Me.ContactEmail) Then
    MsgBox ("Can't create email: no address listed")
    Exit Sub
End If

sWebPath = "mailto:" & Me.ContactEmail

sFullLinkPath = sWebPath
Application.FollowHyperlink sFullLinkPath

End Sub