Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-11-25
23
Medium Priority
?
820 Views
Last Modified: 2012-08-13
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?
0
Comment
Question by:bignadad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 13
  • 7
  • 3
23 Comments
 
LVL 13

Accepted Solution

by:
gbanik earned 1000 total points
ID: 34214708
Modify this code to send mail (even if Outlook is closed)
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

0
 
LVL 31

Expert Comment

by:hnasr
ID: 34214726
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", ....?
0
 
LVL 31

Expert Comment

by:hnasr
ID: 34214743
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.
0
What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

 
LVL 2

Author Comment

by:bignadad
ID: 34214994
Im getting an object/application defined error on this line

        .Attachments.Add "C:\image1.jpg"
0
 
LVL 2

Author Comment

by:bignadad
ID: 34215023
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:\
0
 
LVL 13

Expert Comment

by:gbanik
ID: 34215585
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.
0
 
LVL 2

Author Comment

by:bignadad
ID: 34220479
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
0
 
LVL 2

Author Comment

by:bignadad
ID: 34225583
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.
0
 
LVL 31

Expert Comment

by:hnasr
ID: 34225845
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?
0
 
LVL 2

Author Comment

by:bignadad
ID: 34225850
Yes, That scenario is fine.
0
 
LVL 31

Expert Comment

by:hnasr
ID: 34225959
0
 
LVL 31

Expert Comment

by:hnasr
ID: 34226016
add 2 images to C: drive, f1.jpg and f2.jpg. You may use D: or any permissible path.
0
 
LVL 2

Author Comment

by:bignadad
ID: 34226034
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
0
 
LVL 2

Author Comment

by:bignadad
ID: 34226054
Nevermind its working now... Had to have outlook up and running....

give me just a sec to test further
0
 
LVL 2

Author Comment

by:bignadad
ID: 34226176
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
0
 
LVL 2

Author Comment

by:bignadad
ID: 34226351
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?
0
 
LVL 2

Author Comment

by:bignadad
ID: 34226364
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?
0
 
LVL 31

Assisted Solution

by:hnasr
hnasr earned 1000 total points
ID: 34226391
Missing reference to Outlook Object Library.

Show code editor.
Select menu Tools-References
Tick Microsoft Outlook 12.0 Object Library
Click OK
Run and try.
0
 
LVL 13

Expert Comment

by:gbanik
ID: 34226436
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

0
 
LVL 2

Author Comment

by:bignadad
ID: 34226437
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?
0
 
LVL 2

Author Comment

by:bignadad
ID: 34226440
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....
0
 
LVL 31

Expert Comment

by:hnasr
ID: 34226484
This may be related to User Account Control
Check:
http://technet.microsoft.com/en-us/library/cc709691(WS.10).aspx
0
 
LVL 2

Author Comment

by:bignadad
ID: 34226550
i have UAC turned off (never notify)

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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
If you need a simple but flexible process for maintaining an audit trail of who created, edited, or deleted data from a table, or multiple tables, and you can do all of your work from within a form, this simple Audit Log will work for you.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question