Ms access 获取向动态地址发送电子邮件的访问权限

Ms access 获取向动态地址发送电子邮件的访问权限,ms-access,vba,ms-access-2010,Ms Access,Vba,Ms Access 2010,这是在Access 2010中,我对VBA几乎没有任何经验或熟悉 在我的表单(frmEmailLookup)中,我设置了组合框、列表框和子表单,以便当用户从cmbBuilding中选择一栋建筑时,表单的其余部分填充该建筑的数据,包括该建筑中最多4人的联系电子邮件(lstBuildingRepEmail1、lstBuildingRepEmail2、lstBuildingRepEmail3、lstBuildingRepEmail4)。我需要一个按钮(butEmailRecords)来生成包含子表单(

这是在Access 2010中,我对VBA几乎没有任何经验或熟悉

在我的表单(frmEmailLookup)中,我设置了组合框、列表框和子表单,以便当用户从cmbBuilding中选择一栋建筑时,表单的其余部分填充该建筑的数据,包括该建筑中最多4人的联系电子邮件(lstBuildingRepEmail1、lstBuildingRepEmail2、lstBuildingRepEmail3、lstBuildingRepEmail4)。我需要一个按钮(butEmailRecords)来生成包含子表单(qryBuildingRealookup)查询的电子邮件作为附件。我可以设置一个宏来关闭某些东西,但它不允许动态电子邮件地址。我不希望我的用户必须深入程序才能进行更新

非常感谢您的任何帮助,我知道我需要很多代码编写方面的帮助

以下是我尝试过的:

    Option Compare Database
Private Sub butEmailRecords_Click()
Dim outputFileName As String
outputFileName = CurrentProject.Path & "\BuildingInventory" & ".xlsx"
DoCmd.TransferSpreadsheet acExport,      acSpreadsheetTypeExcel9, "qryBuildingAreaLookup",     outputFileName, True

On Error GoTo Error_Handler
Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

Dim rs As DAO.Recordset
Set rs = CurrentDb.OpenRecordset("qryBuildinAreaLookup")
With rs

With objEmail
.To = tblBuilding.BuildingRep1
.To = tblBuilding.BuildingRep2
.To = tblBuilding.BuildingRep3
.To = tblBuilding.BuildingRep4
.Subject = "Look at this sample attachment"
.body = "The body doesn't matter, just the attachment"
.Attachments.Add "L:\Administration\FacilityInventoryDatabase\BuildingInventory.xls    x"
.Send
'.ReadReceiptRequested
End With
Exit_Here:
Set objOutlook = Nothing
Exit Sub

Error_Handler:
MsgBox Err & ": " & Err.Description
Resume Exit_Here
End Sub

以下是我使用的基本内容:

'Refers to Outlook's Application object
Dim appOutlook As Object

'Refers to an Outlook email message
Dim appOutlookMsg As Object

'Refers to an Outlook email recipient
Dim appOutlookRec As Object

'Create an Outlook session in the background
Set appOutlook = CreateObject("Outlook.Application")

'Create a new empty email message
Set appOutlookMsg = appOutlook.CreateItem(olMailItem)

'Using the new, empty message...
With appOutlookMsg

'SQL statement to grab emails

Set recordset = currentdb.openrecordset('SQL statement')

Do While Not recorset.EOF
Set appOutlookRec = .Recipients.Add(recordset.Email)
appOutlookRec.Type = olTo
recordset.MoveNext
Loop

.Subject = ....
.Body = ....
.Send

End With

这是我使用的基础。我是一个初学者,所以这可能不是最好的方法,但应该是一个开始。(我还必须在参考库中添加Microsoft Olook。)

我使用CDO对象发送消息,因为我不喜欢依赖Outlook(做任何事情)

这里有一篇关于使用CDO发送邮件(包括可下载的VBA代码)的综合文章:


欢迎使用Stack Overflow(堆栈溢出)-通常情况下,您需要发布一些针对某个特定问题尝试过的代码,但这些代码不起作用-这个问题非常模糊,要求其他人为您完成工作-这可能会被关闭。我有一个电子邮件宏,它使用一个循环来获取用户的所有电子邮件它需要经过的部门。那么唯一需要更新的是员工列表。谢谢TKEyi60。您是否使用EMailDatabaseObject宏?如果是,如何获得“收件人”在set resordset=currentdb.openrecordset一节中,引用表中的字段?如果有,会引发什么错误?或者它做/不做什么?这是我要作为附件发送的查询,对吗?我想你可以将其设置为附件,但我不确定如何通过VBA实际附加任何内容。我只写我的查询将提取电子邮件地址并将其放入收件人字段。谢谢。我将再次尝试询问我的电子邮件地址。