My Assistant
![]() ![]() |
|
|
Mar 15 2012, 08:11 AM
Post
#1
|
|
|
UtterAccess Guru Posts: 696 |
I have the following code to send emails from Access:
CODE Dim olApp As Outlook.Application Dim olMail As MailItem Dim objOutlookAttach As Outlook.Attachment Set olApp = New Outlook.Application Set olMail = olApp.CreateItem(olMailItem) With olMail .BodyFormat = olFormatHTML .To = Left(pubMessageRecipientsToAddress, Len(pubMessageRecipientsToAddress) - 1) .CC = "" .Subject = pubMessageSubject .Body = pubMessageBody End With 'Add Attachments Dim db As DAO.Database Dim rstAttachements As DAO.Recordset Set db = CurrentDb() Set rstAttachments = db.OpenRecordset("Select EMailAttachment from tblTempSendEMailAttachments") If rstAttachments.RecordCount > 0 Then With rstAttachments .MoveLast .MoveFirst Do Until .EOF If DoesFileExist(rstAttachments!EMailAttachment) Then With olMail .Attachment.Add (rstAttachments!EMailAttachment) End With End If .MoveNext Loop End With End If With olMail .Save .Send End With Set olMail = Nothing Set olApp = Nothing MsgBox "Mail Sent!", vbOKOnly, "Mail Sent" However the code under "Add Attachments" does not work. I get an error in line ".Attachment (rstAttachments!EMailAttachment)" I write the url of every file to be attached to the email as records in a table called "tblTempSendEMailAttachments". I want to loop through the table as attach the files to the email Thanks in advance This post has been edited by TimTDP: Mar 15 2012, 08:12 AM |
|
|
|
Mar 15 2012, 08:15 AM
Post
#2
|
|
|
UtterAccess Ruler Posts: 1,090 |
If your field EMailAttachment is of Attachment type, you need to open it as recordsource.
|
|
|
|
Mar 15 2012, 11:33 AM
Post
#3
|
|
|
UtterAccess Guru Posts: 696 |
It is not of attachment type
It is text, 255 long |
|
|
|
Mar 15 2012, 11:42 AM
Post
#4
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
i dont think it should be using olmail i think it should be olappattach.attachments.add
|
|
|
|
Mar 15 2012, 11:45 AM
Post
#5
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
here is a snippet of what i use to send attachments successfully
CODE Set objOutlook = GetObject(, "Outlook.Application")
Set objOutlook = CreateObject("Outlook.Application") Set objOutlookMsg = objOutlook.CreateItem(olMailItem) With objOutlookMsg Set objOutlookRecip = .Recipients.Add(somebody@somewhere.com) objOutlookRecip.type = olTo .Subject = "here you go" .Body = "This information is being automatically generated " & vbCrLf _ & "If you have any issues please contact the sender" .Importance = olImportanceHigh 'High importance Set objOutlookAttach = .Attachments.Add(strpath & "somefilexls") |
|
|
|
Mar 15 2012, 12:02 PM
Post
#6
|
|
|
UtterAccess Guru Posts: 696 |
What do you dimension objOutlookAttach as?
|
|
|
|
Mar 15 2012, 12:06 PM
Post
#7
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
i know it looks and sounds wierd. but I dont. i use exactly what i have shown (with real data anyway)
|
|
|
|
Mar 15 2012, 12:10 PM
Post
#8
|
|
|
UtterAccess VIP Posts: 8,191 From: CT |
i think it is because it is part of the object objoutlook I dont dim the objoutlookrecip either. and I use Option Explicit on the module so if it was "wrong' it wouldnt let me
|
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 18th June 2013 - 10:07 PM |