Hi There!
I have a form from which to send emails in Access
I am trying to include a subfrom. The subform holds the file paths of one or multiple attachments, which I would like to include in my email.
I am trying to write code which loops through each record in this subform and includes each specified file in the email to be send. I am having a hard time doing this as my VB skills are more trial and error than effective programming.
Here is the code (which makes my application freeze for unknown reasons to me)
Maybe one of you can tell me why...
--------------------------------------------------------
Dim App As Outlook.Application
Dim Message As Outlook.MailItem
Set App = CreateObject("Outlook.Application")
Set Message = App.CreateItem(olMailItem)
With Message
.To = rst(EmailAddressField)
.Importance = olImportanceHigh
.SentOnBehalfOfName = "Email@email.com"
.subject = Me.Controls(MsgSubjectField)
.Body = strMsgToSend
End With
' Here is where the Problem lies:
Dim rs As DAO.Recordset
Dim F As Form
Set F = CodeContextObject
Set rs = F!Sub_Attachments.RecordsetClone
Do Until rs.BOF
With Message
.Attachments.Add rs!File_Path
End With
rs.MoveNext
Loop
With Message
.Save
End With
Set App = Nothing
Set Message = Nothing
--------------------------------------------------------
I have a form from which to send emails in Access
I am trying to include a subfrom. The subform holds the file paths of one or multiple attachments, which I would like to include in my email.
I am trying to write code which loops through each record in this subform and includes each specified file in the email to be send. I am having a hard time doing this as my VB skills are more trial and error than effective programming.
Here is the code (which makes my application freeze for unknown reasons to me)
Maybe one of you can tell me why...
--------------------------------------------------------
Dim App As Outlook.Application
Dim Message As Outlook.MailItem
Set App = CreateObject("Outlook.Application")
Set Message = App.CreateItem(olMailItem)
With Message
.To = rst(EmailAddressField)
.Importance = olImportanceHigh
.SentOnBehalfOfName = "Email@email.com"
.subject = Me.Controls(MsgSubjectField)
.Body = strMsgToSend
End With
' Here is where the Problem lies:
Dim rs As DAO.Recordset
Dim F As Form
Set F = CodeContextObject
Set rs = F!Sub_Attachments.RecordsetClone
Do Until rs.BOF
With Message
.Attachments.Add rs!File_Path
End With
rs.MoveNext
Loop
With Message
.Save
End With
Set App = Nothing
Set Message = Nothing
--------------------------------------------------------