MS Access Email Using VBA - attachment errors

sshacreaw

New Member
Joined
Feb 22, 2008
Messages
3
I have written a program to loop through a table and gather email address, on each loop (each new email address) an email is sent with a series of attachments. My problem is that I recently downloaded a bunch of windows updates and now my emails won't send. I wasn't sure if anyone else was having the same issue or not. It worked perfectly fine until I ran the updates. I have a snipet of code attached below. I also know that it is the attachments causing a problem because as soon as I comment out the attachments it runs through just fine.

** On another note, when the program then errors and I click debug or end, a bunch of the letter "n" fills a couple lines and then just quits. **

Thanks in advance for your help!

Private Sub Command0_Click()

Dim myolApp As Outlook.Application
Dim myItem As Object

Dim myNameSpace As Object
Dim myFolder As Object
Dim myAttachments, myRecipient As Object
Dim recipient As String
Dim file_name As String
Dim mySubject As Object
Dim dbs As Object
Dim rst As Object
Dim rst2 As Object
Dim strSQL As String

Set db = CurrentDb
Set rst = db.OpenRecordset("emailtable", dbOpenDynaset)

rst.MoveFirst
Do While Not rst.EOF
'MsgBox (rst!Address)

'recipient = rst!Address
Set myolApp = CreateObject("Outlook.Application")
Set myItem = myolApp.CreateItem(olMailItem)

' This addresses it
myItem.To = rst!Address

'This gives it a subject
myItem.Subject = "test subject"

'This gives it the body
myItem.Body = "test body new"
'myItem.Attachments.Add ("C:\Documents and Settings\ss44151\Desktop\NDA 2\NDA Agreement Request-new.doc")
'myItem.Attachments.Add ("C:\Documents and Settings\ss44151\Desktop\NDA 2\MCG Mutual Nondisclosure Agmt 2-19-08.pdf")
'Set myAtachments = myItem.Attachments.Add("C:\Documents and Settings\ss44151\Desktop\NDA 2\Recertification Letter.rtf")
'myItem.Attachments.Add ("C:\Documents and Settings\ss44151\Desktop\NDA 2\Supplier Technology Survey.doc")
'myItem.Attachments.Add ("C:\Documents and Settings\ss44151\Desktop\NDA 2\SUPPLIER CONTACT LIST 2007.xls")


'myItem.DeleteAfterSubmit = True

'This sends it!
myItem.Send
rst.MoveNext
Loop



End Sub
 
Last edited:

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi

Are you able to roll your system back using system restore? And then maybe introduce the updates one at a time to see which one causes the problem? I'm thinking it might be a security update that prevents applications sending e-mails with attachments?

If you step through the code, which line gives an error?

On a side note, I noticed you have used early binding for your outlook application - you can also use the proper variable types for myItem (Outlook.MailItem) and
myAttachments (Outlook.Attachment) and myRecipient (Outlook.Recipient) - assuming you are actually using the last 2 in the real version of your code, instead of using the generic 'Object' variable type.

I would also recommend you move the this line of your code:
Code:
Set myolApp = CreateObject("Outlook.Application")
to outside of the rst loop (to after the 'Set rst' line) - it only needs to be set once - not every time you run through the loop.

Andrew
 
Upvote 0
I will see what i can try. I have good access to my computer, but it is a company owned so I will see what I can do. I did change those vaiable definitions. Thanks for your help!
 
Upvote 0
I figured out the problem. I didn't realize it, but the company also installed an app that works with outlook for sending large files... Accellion... This was causing issues when attaching files to emails coming out of VBA. I uninstalled Accellion and everything works fine now. Thanks for your help!
 
Upvote 0

Forum statistics

Threads
1,215,343
Messages
6,124,394
Members
449,155
Latest member
ravioli44

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top