我是VBA的新手,我正在尝试创建一些代码,用于通过MS Access中的表单发送详细信息
该表单称为客户,字段为ID,名称和电子邮件。
我使用了以下代码从其他网站获取并且我一直收到错误
Option Compare Database
Private Sub Command7_Click()
Dim ID, name, email
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
ID = Customer!ID
name = Customer!name
email = Customer!email
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)
With objEmail
.To = email
.Subject = ID
.send
End With
Set objEmail = Nothing
objOutlook.Quit
End Sub
答案 0 :(得分:0)
除非您设置对Outlook库的引用,否则您将收到错误。
尝试使用它,它使用后期绑定到Outlook对象。
Private Sub Command7_Click()
Dim ID, name, email 'You should probably make these something other than variants
Dim objOutlook As Object
Dim objEmail As Object
ID = Customer!ID
name = Customer!name
email = Customer!email
Set objOutlook = CreateObject("Outlook.Application")
Set objEmail = objOutlook.CreateItem(0) '0 is the enum for olMailItem
With objEmail
.To = email
.Subject = ID
.send
End With
Set objEmail = Nothing
set objOutlook = nothing
End Sub