我有一个数据库,除其他外,该数据库存储我的客户的医疗申报单。
表单从外部存储在文件夹(c:\...\medical form
)中,并命名为(DDMMYYYY Fname Lname
)。该文件名(不是strpath
)数据存储在[med forms]
中。
在父表单(courses
)上,我试图在子表单[med forms]
上放置一个循环显示[courses customer subform]
的按钮,并将它们附加到一封电子邮件中,然后将其发送给我。
我在遍历表格并连接strpath
和strfile
来附加这些文档时遇到了一些麻烦,由于我的编码知识很差,现在让我感到困惑。
希望你们当中有一个可爱的人可以提供帮助!
Dim appOutLook As Outlook.Application
Dim MailOutLook As Outlook.MailItem
Dim strpath As String
Dim strfile As String
Dim varSubject As Variant
Dim varGroup As Variant
Dim varBody As Variant
Dim stratt As String
strpath = "C:\...\Medical forms"
varSubject = "Med forms " & (Me.[Title]) & (Me.[Start])
varBody = "email body TBC"
With Me.[courses customer subform].Form.RecordsetClone
If (.RecordCount) Then
.MoveFirst
Do Until .EOF
If Len(![Med form]) Then
stratt = stratt & strpath & ![Med form]
End If
.MoveNext
Loop
If Len(strEmail) Then
Set appOutLook = CreateObject("Outlook.Application")
Set MailOutLook = appOutLook.CreateItem(olMailItem)
With MailOutLook
.BodyFormat = olFormatRichText
.To = "[email protected]"
.Subject = varSubject
.HTMLBody = varBody
.Attachments.Add (strpath & strfile)
.Display
End With
End sub
因为您已经在使用后期绑定(CreateObject("Outlook.Application")
),所以我建议在您的Sub的其余部分中使用后期绑定(避免需要添加库引用),并根据以下内容提出一些建议:
Sub EmailForms()
Dim strPth As String: strPth = "C:\...\Medical forms\"
Dim strSub As String: strSub = "Med forms " & Me.[Title] & Me.[Start]
Dim strBdy As String: strBdy = "email body TBC"
Dim rsRst As DAO.Recordset
Set rsRst = Me.[courses customer subform].Form.RecordsetClone
If Not rsRst.EOF Then
rsRst.MoveFirst
Dim olApp As Object
Set olApp = CreateObject("Outlook.Application")
With olApp.CreateItem(0) 'olMailItem
.BodyFormat = 3 'olFormatRichText
.to = "[email protected]"
.Subject = strSub
.HTMLBody = strBdy
With .Attachments
Do Until rsRst.EOF
If rsRst![Med form] <> vbNullString Then
.Add strPth & rsRst![Med form]
End If
rsRst.MoveNext
Loop
End With
.Display
End With
End If
rsRst.Close
End Sub