Link to home
Start Free TrialLog in
Avatar of Addie Baker
Addie BakerFlag for United States of America

asked on

Need to Send Email From MS Access Form (Using VBA) With Mulitiple Pictures from Network Location using "Default Outlook Program"

I have a Form that i would like to add a button to so i can generate and email with pictures for the "BAM" Number shown. The BAM number is my identifier for the pictures being sent... Sometime it will be 1 picture sometimes it might be 10. They are already reduced in file size and just need to be pullled from certain network location and attached to email....

I am using Access 2010 and i have tried adding COM and Access Add-Ins with no luck....
i have tried using this command
Dim MyOutlook As Outlook.Application
But i guess its calling for the addin that is not there?
ASKER CERTIFIED SOLUTION
Avatar of gbanik
gbanik
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Hamed Nasr
Do you intend to send one message with more than one attachment to one Recipient?
Can we assume pictures with known paths, like "C:\p1.jpg", "C:\p2.jpg", ....?
I can see  gbanik assumed the paths and multiple recipients. Check his comment!

Use olTo instead of 1 for type, and olCC instead of 2.
Avatar of Addie Baker

ASKER

Im getting an object/application defined error on this line

        .Attachments.Add "C:\image1.jpg"
btw i also go the error on this line
        oReci.Type = 1
but when changine to olTo it fixed....

Also, i have the image1.jpg on the c:\
The best way to code for Outlook mails is to set the mail object to visible and then make alterations (and step through breakpoint) ... so you know which code is doing what.

To do so just use
olMail.display
in the code.

Please debug the code and check where exactly the error is coming. This will help resolve easily.
Little confused on the breakpoints.. i tried the olMail.display and still getting same error as above..

it does not seem to process .Attachments.Add
If i cant send through outlook is there another method?

i basically need a user to click a button and attach the pictures to an email to send to a recipient they will type in.
Assume environment:

Disk drive C:
Image files C:\f1.jpg, C:\f2.jpg
A form: Form1 with a textbutton: txtEmail
A button:cmdSend

cmdSend_Click to send email to recipient in txtEmail with f1, mand f2 images attached.
Is this scenario ok?
Yes, That scenario is fine.
add 2 images to C: drive, f1.jpg and f2.jpg. You may use D: or any permissible path.
tried to enter an email address and clicked butt and it gives me following error

Run-Time error 287
Application-defined or object-defined error

highlights this line
Set objOutlookRecip = objOutlookMsg.Recipients.Add(Me![txtEmail])

when i rollover Set objOutlookRecip is says it = Nothing
Nevermind its working now... Had to have outlook up and running....

give me just a sec to test further
it works out of the dbase you sent but when i use your code in my database im getting an error

Compile Error
User-defined type not defined

It highlights
Private Sub cmdSend_Click()

and the following text is selected
objOutlook As Outlook.Application
Still trying to see why it wont work in my database, and not having much luck..

when i open your file it shows up as a mdb and mine is a accdb (later version)
this wouldn't be conflicting would it?
i guess so.. i tried copying your frm from access 2000 version into a new blank database and got same error....

this has to be done in a access 2000 environment?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Again bignadad, could you run my code again? You should be able to do it with this code. Try after adding references.
Option Explicit

Public Sub SendMail()

    Dim olApp
    Set olApp = CreateObject("Outlook.Application")

    Dim olMail, oReci
    Set olMail = olApp.CreateItem(0)

    With olMail
        
        Set oReci = .Recipients.Add("oneperson@gmail.com")
        oReci.Type = 1

        Set oReci = .Recipients.Add("test123@yahoo.com")
        oReci.Type = 2

        .Subject = "This is a Test"
        .Body = "This is the body of the message." & vbCrLf & vbCrLf

        .Attachments.Add "C:\image1.jpg"
        .Attachments.Add "C:\image2.jpg"

        For Each oReci In .Recipients
            oReci.Resolve
        Next

        '.Display
        .Save
        .Send
        
    End With
    Set olApp = Nothing

End Sub

Open in new window

Sweet.. works great

one more question... when outlook comes up it shows a allow/deny security windows that i have to click 3 times before it will send email.. any way to turn that off?
gbanik

your code would have worked fine .. my biggest problem was i didnt have outlook setup and didnt have it in references of visual basic...

thanks for everyone's help
i do have another question i am submitting that i need help figuring out....
This may be related to User Account Control
Check:
http://technet.microsoft.com/en-us/library/cc709691(WS.10).aspx
i have UAC turned off (never notify)

i looked within outlook security settings and didnt see anything there either