vba - 从 Access 发送电子邮件

标签 vba ms-access outlook

我正在尝试开发一个数据库,供教师在需要上课时记录应用程序(我会用 SQL 执行此操作,但目前不能)。

我希望数据库在提出申请时通知某位员工。选择工作人员将通过查询驱动的组合框完成。查询的原因是我只希望特定员工收到此通知 - 主要是那些管理其他员工的人。

一旦选择了该员工,我希望提出申请的人点击一个按钮,然后会向组合框中选择的人发送一封电子邮件。

我看到 Outlook 闪烁了一下,然后什么都没做。

这是我目前所拥有的,DLookup 使用在组合框中选择的员工,然后在员工表中查找电子邮件地址:

Private Sub Command788_Click()
    Dim Email_Note As Variant
    Email_Note = DLookup("Email", "Staff", Forms![Cover Application Form]!Combo767)
    Dim olLook As Outlook.Application
    Dim olNewEmail As Outlook.CreateItem
    Dim StrContactEmail As String
    Set olLook = New Outlook.Application
    Set olNewEmail = olLook.CreateItem(olMailItem)
    strEmailSubject = "Application for Cover: Line Manager Notification"
    strEmailText = "Something in here..."
    StrContactEmail = "Email_Note"
    olNewEmail.Display
End Sub

最佳答案

您应该确保在 VBA 编辑器的工具选项卡中引用了 Outlook 库。看起来您还为正文和主题创建了字符串,但没有声明它们。与其将它们声明为字符串变量,不如设置 外观。 body 等到适当的字符串,如下所示。

email_note 声明为变量后,您无需用引号将其封装起来。我以为那是电子邮件地址?

不再需要 strContactEmail,我看不到它用在什么地方。

Private Sub Command788_Click()
Dim Email_Note As Variant
Email_Note = DLookup("Email", "Staff", Forms![Cover Application Form]!Combo767)
Dim olLook As Outlook.Application
Dim olNewEmail As Outlook.mailItem
'Dim StrContactEmail As String
Set olLook = New Outlook.Application
Set olNewEmail = olLook.CreateItem(olMailItem) 
   olNewEmail.Subject="Application for Cover: Line Manager Notification" 
   olNewEmail.Body = "Something in here..."
   olNewEmail.To = email_note
   olNewEmail.Send
Set olNewEmail = Nothing
Set olLook = Nothing
End Sub

关于vba - 从 Access 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37002301/

相关文章:

excel - 使特定列中的所有事件单元格为其绝对值

vba - 从特定模块更改复选框的字体属性 "Strikethrough"不起作用

VBA - 在一行中设置多维数组值

sql - 大型数据集的报告工具/查看器

PHP+MS Access : Wildcard * being taken as a string when querying through PHP?

excel - 如何在整个工作簿范围下进行Worksheet_SelectionChange?

ms-access - 以 PTRSAFE 和 UNICODE 安全方式从 VBA 将 LPCTSTR 参数传递给 API 调用

javascript - 使用 Javascript 在 Microsoft Outlook 中创建 HTML 电子邮件

outlook - 如何访问 Office 插件中的后台复选框值?

excel - 在 VBA 中更改 HTML 电子邮件正文字体类型和大小