gpt4 book ai didi

vba - 从 Access 发送电子邮件

转载 作者:行者123 更新时间:2023-12-01 12:28:32 25 4
gpt4 key购买 nike

我正在尝试开发一个数据库,供教师在需要上课时记录应用程序(我会用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com