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

x
?
Solved

Need to Send a Certain amount of pictures as attachments via Email in Access 2010

Posted on 2010-11-28
9
Medium Priority
?
431 Views
Last Modified: 2012-05-10
i am using the following code to generate an email from my form by clicking a button

What i need it this

the txtSearchBAM value will determine what pictures to send

but that value has anywhere from 1 to 15 pictures...

All pictures are located at this address
C:\Users\Addie\Desktop\Droid\Database\

The next folder is the BAM number and then that folder contains the pictures...

how can i make this code send to how many ever pictures are in the specified folder?
Dim objOutlook As Outlook.Application
    Dim objOutlookMsg As Outlook.MailItem
    Dim objOutlookRecip As Outlook.Recipient
    Dim objOutlookAttach As Outlook.Attachment
    Dim TheAddress As String

    Set objOutlook = CreateObject("Outlook.Application")
    
    Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
            Set objOutlookRecip = objOutlookMsg.Recipients.Add(Me![txtSendemail])
    
    With objOutlookMsg
        objOutlookRecip.Type = olTo
        
        .Subject = Me.txtMake.Value & "Pictures From Baker Abilene Machine" ' can be a text box on form
        .Body = "Sending many photos" ' can be a text box on form
        
        Set objOutlookAttach = .Attachments.Add("C:\Users\Addie\Desktop\Droid\Database\" & (Me.txtSearchBAM.Value) & "\1.jpg")
        Set objOutlookAttach = .Attachments.Add("C:\Users\Addie\Desktop\Droid\Database\" & (Me.txtSearchBAM.Value) & "\2.jpg")
        ' repeat for images
        .Send
    End With
    Set objOutlookMsg = Nothing
    Set objOutlook = Nothing

Open in new window

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
  • 5
  • 3
9 Comments
 
LVL 85
ID: 34226891
You can use the Dir function to loop through:

Dim sFile As String

sFile = Dir("C:\Users\Addie\Desktop\Droid\Database\" & (Me.txtSearchBAM.Value) & "\*.jpg")

Do Until Len(sFile)=0
    .Attachments.Add("C:\Users\Addie\Desktop\Droid\Database\" & (Me.txtSearchBAM.Value) & "\" & sFile)
  Dir
Loop

0
 
LVL 2

Author Comment

by:bignadad
ID: 34226996
Getting this error on the .attachments.Add LINE

Run-time error -2147467259 (80004005)

Cannot create file: 1.jpg. right-click the folder you want to create the file in and then click properties on the shortcut menu to check you permissions for the folder

0
 
LVL 2

Author Comment

by:bignadad
ID: 34226998
oh and i do get the security alert from outlook before it gives me the error...
0
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 34227822
<No Points wanted>

..."oh and i do get the security alert from outlook before it gives me the error."
This is unrelated to your main question , but I will address it here.

This is the Outlook Automation Security popup.
It can be bypassed by using a product like this:
 http://www.contextmagic.com/express-clickyes/
...Or by using a product that bypassed the entire Oultook Client issue (LSM can tell you more some of these products)

;-)

JeffCoachman
0
 
LVL 85
ID: 34229161
I use vbMAPI from www.everythingaccess.com. It's simple and intuitive, and will take care of the security prompt.

Did you do as the error message suggested and check the Folder permissions? It looks as if you're on a Vista or Win7 box, so be very careful where you place these items. It looks as if you're attempting to "create" a file in some fashion

Check the format of your string. To do that, add this line immediately before your Attachment add line:

Debug.Print C:\Users\Addie\Desktop\Droid\Database\" & (Me.txtSearchBAM.Value) & "\" & sFile

This will print the fully formed string to the Immediate window. Paste that value back here.

0
 
LVL 2

Author Comment

by:bignadad
ID: 34230220
okay, changed my locations around a bit to match what i needed and below is what i have

i get the following error when attempting to send

Run time Error 5
Invalid procedure call or argument
-highlights Dir

IF i remove the Dir i get the following error
run time error 2147467259 (800004005)
the attachment size exceeds the allowable limit
-highlights the attachment line
sFile = Dir("Z:\BAMEQ\" & (Me.txtSearchBAM.Value) & "\*.jpg")

    Do Until Len(sFile) = 0
    .Attachments.Add ("Z:\BAMEQ\" & (Me.txtSearchBAM.Value) & "\" & sFile)
     Dir
    Loop

Open in new window

0
 
LVL 85

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 2000 total points
ID: 34230610
Sorry, my brain was rusty this morning:

    Do Until Len(sFile) = 0
    .Attachments.Add ("Z:\BAMEQ\" & (Me.txtSearchBAM.Value) & "\" & sFile)
     sFile = Dir
    Loop

This will take care of the Error 5.

As to your other error, see this post:

http://tsoorad.blogspot.com/2008/01/outlook-attachment-size-error.html

If that doesn't fix it, then I'm not sure there's a lot that can be done. Are you using an Exchange server to manage your email? If so, talk with the person who oversees that to see if there is a setting that could be affecting this.


0
 
LVL 2

Author Comment

by:bignadad
ID: 34230707
It worked that time with the fixed code....

not to try to disable security warning...

thanks for your help :)
0
 
LVL 2

Author Comment

by:bignadad
ID: 34230742
boag2000's method worked great to bypass security.. thanks
0

Featured Post

Technology Partners: 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

This article lists the top 5 free OST to PST Converter Tools. These tools save a lot of time for users when they want to convert OST to PST after their exchange server is no longer available or some other critical issue with exchange server or impor…
The core idea of this article is to make you acquainted with the best way in which you can export Exchange mailbox to PST format.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

730 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