473,395 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Can you attach multiple photos in Access and generate an email?

anoble1
245 128KB
Hi,

I am writing a database that I want to be able to hit a button and a email generates and pulls multiple photos in a specified folder on the network and throw them in a email for me to send. The photos are .jpg

Is there a way to have multiple picture attachments? I think DoCmd.OutputTo acOutputReport only does 1 record according to a post I was reading on here earlier today. So, just wanting them all attached to the email.

Any help?
Thanks,
-Andy
Aug 29 '12 #1

✓ answered by TheSmileyCoder

Here is some code I use to attach anywhere from 2 to 40 various files to an email.

I have had to remove certain bits from the code that wouldn't make sense in this context, so if the code is broken I probably removed to much.

Expand|Select|Wrap|Line Numbers
  1. Public Function CreateEmail() As Boolean
  2. 'On Error GoTo errHandler
  3.  
  4.    Dim rsFiles As DAO.Recordset
  5.    Set rsFiles = CurrentDb.OpenRecordset("SELECT * from tbl_ReviewCommentSheet where bChecked ORDER BY tx_TransmittalID, RID", dbOpenSnapshot, dbReadOnly)
  6.  
  7.    'If nothing selected exit
  8.       If rsFiles.EOF Then GoTo ExitFunction
  9.  
  10.    'Open outllook and start email
  11.       Dim oMail As Outlook.MailItem
  12.       Dim oApp As Outlook.Application
  13.       Set oApp = New Outlook.Application
  14.       Set oMail = oApp.CreateItem(olMailItem)
  15.       oMail.HTMLBody = "<H3><B>Dear Sirs</B></H3>" & _
  16.               "Please find enclosed our comments to the above mentioned Transmittals.<br><br>" & _
  17.                GetSignature 'GetSignature custom function to load users Auto-signature
  18.       Dim oRecipient As Outlook.Recipient
  19.       'Add the recipients
  20.          Set oRecipient = oMail.Recipients.Add("FakeName@FakeCompany.com")
  21.          oRecipient.Type = olTo
  22.  
  23.          Set oRecipient = oMail.Recipients.Add("FakeName2@FakeCompany2.dk")
  24.          oRecipient.Type = olCC
  25.       oMail.Recipients.ResolveAll
  26.  
  27.    'Loop through adding attachments
  28.       Dim strPath As String
  29.       Dim strWorkPath As String
  30.       strWorkPath = "G:\DATA\Comments to transmittals\LetterCreator\WorkFolder\"
  31.       Dim strLastTrans As String
  32.       Dim strSubject As String
  33.       strSubject = "Comments to Transmittals"
  34.       Do While Not rsFiles.EOF
  35.          If strLastTrans <> rsFiles!tx_TransmittalID Then
  36.             strLastTrans = rsFiles!tx_TransmittalID
  37.             strSubject = strSubject & " " & rsFiles!tx_TransmittalID & ","
  38.          End If
  39.  
  40.  
  41.  
  42.          strPath = "G:\DATA\Comments to transmittals\Pending\" & rsFiles!tx_TransmittalID & "\"
  43.          'Excel first
  44.             oMail.Attachments.Add strPath & rsFiles!tx_ExcelFile, olByValue
  45.             'now pdf
  46.             oMail.Attachments.Add strWorkPath & rsFiles!tx_PdfFile, olByValue
  47.             Kill strWorkPath & rsFiles!tx_PdfFile
  48.          rsFiles.MoveNext
  49.       Loop
  50.    strSubject = Left(strSubject, Len(strSubject) - 1)
  51.    oMail.Subject = strSubject
  52.    oMail.Display
  53.    CreateEmail = True
  54.  
  55. ExitFunction:
  56.    rsFiles.Close
  57.    Set rsFiles = Nothing
  58.    Exit Function
  59.  
  60. exitFail:
  61.    On Error Resume Next
  62.    GoTo ExitFunction
  63.  
  64. errHandler:
  65.    MsgBox Err.Number & " - " & Err.Description
  66.    Resume exitFail
  67. End Function

6 1983
twinnyfo
3,653 Expert Mod 2GB
There is another method for sending e-mails, I'm trying to dig up an example to show you....
Aug 29 '12 #2
anoble1
245 128KB
That would be great!
Aug 29 '12 #3
zmbd
5,501 Expert Mod 4TB
I know the basic command is fairly limited.
Using automation you can do alot more:
http://support.microsoft.com/kb/161088

Here's the trick... I haven't used this to send more than one attachment so you'll have to look at the code a tad.

So if we use a record set to pull the attachments then the code might be changed to something like:

Expand|Select|Wrap|Line Numbers
  1. 'do the open record set stuff and check to make
  2. 'sure there are attachments then something like
  3. 'modify the MS Code to read the record set
  4. '
  5. Do While Not zrs.EOF
  6. AttachmentPath = _
  7.    zrs.Fields("thefieldwithattachmentpathhere")
  8. Set objOutlookAttach = _
  9.    .Attachments.Add(AttachmentPath)
  10. zrs.MoveNext
  11. Loop
  12. '
  13. 'cleanup code would follow
Once again, this is untested and based upon the code from MS from the above link.

-z
Aug 29 '12 #4
TheSmileyCoder
2,322 Expert Mod 2GB
Here is some code I use to attach anywhere from 2 to 40 various files to an email.

I have had to remove certain bits from the code that wouldn't make sense in this context, so if the code is broken I probably removed to much.

Expand|Select|Wrap|Line Numbers
  1. Public Function CreateEmail() As Boolean
  2. 'On Error GoTo errHandler
  3.  
  4.    Dim rsFiles As DAO.Recordset
  5.    Set rsFiles = CurrentDb.OpenRecordset("SELECT * from tbl_ReviewCommentSheet where bChecked ORDER BY tx_TransmittalID, RID", dbOpenSnapshot, dbReadOnly)
  6.  
  7.    'If nothing selected exit
  8.       If rsFiles.EOF Then GoTo ExitFunction
  9.  
  10.    'Open outllook and start email
  11.       Dim oMail As Outlook.MailItem
  12.       Dim oApp As Outlook.Application
  13.       Set oApp = New Outlook.Application
  14.       Set oMail = oApp.CreateItem(olMailItem)
  15.       oMail.HTMLBody = "<H3><B>Dear Sirs</B></H3>" & _
  16.               "Please find enclosed our comments to the above mentioned Transmittals.<br><br>" & _
  17.                GetSignature 'GetSignature custom function to load users Auto-signature
  18.       Dim oRecipient As Outlook.Recipient
  19.       'Add the recipients
  20.          Set oRecipient = oMail.Recipients.Add("FakeName@FakeCompany.com")
  21.          oRecipient.Type = olTo
  22.  
  23.          Set oRecipient = oMail.Recipients.Add("FakeName2@FakeCompany2.dk")
  24.          oRecipient.Type = olCC
  25.       oMail.Recipients.ResolveAll
  26.  
  27.    'Loop through adding attachments
  28.       Dim strPath As String
  29.       Dim strWorkPath As String
  30.       strWorkPath = "G:\DATA\Comments to transmittals\LetterCreator\WorkFolder\"
  31.       Dim strLastTrans As String
  32.       Dim strSubject As String
  33.       strSubject = "Comments to Transmittals"
  34.       Do While Not rsFiles.EOF
  35.          If strLastTrans <> rsFiles!tx_TransmittalID Then
  36.             strLastTrans = rsFiles!tx_TransmittalID
  37.             strSubject = strSubject & " " & rsFiles!tx_TransmittalID & ","
  38.          End If
  39.  
  40.  
  41.  
  42.          strPath = "G:\DATA\Comments to transmittals\Pending\" & rsFiles!tx_TransmittalID & "\"
  43.          'Excel first
  44.             oMail.Attachments.Add strPath & rsFiles!tx_ExcelFile, olByValue
  45.             'now pdf
  46.             oMail.Attachments.Add strWorkPath & rsFiles!tx_PdfFile, olByValue
  47.             Kill strWorkPath & rsFiles!tx_PdfFile
  48.          rsFiles.MoveNext
  49.       Loop
  50.    strSubject = Left(strSubject, Len(strSubject) - 1)
  51.    oMail.Subject = strSubject
  52.    oMail.Display
  53.    CreateEmail = True
  54.  
  55. ExitFunction:
  56.    rsFiles.Close
  57.    Set rsFiles = Nothing
  58.    Exit Function
  59.  
  60. exitFail:
  61.    On Error Resume Next
  62.    GoTo ExitFunction
  63.  
  64. errHandler:
  65.    MsgBox Err.Number & " - " & Err.Description
  66.    Resume exitFail
  67. End Function
Aug 29 '12 #5
twinnyfo
3,653 Expert Mod 2GB
Smiley - you beat me to the punch. That was the type of code I was looking for. It's the only way I know to include multiple attachments.... Thanks!
Aug 29 '12 #6
TheSmileyCoder
2,322 Expert Mod 2GB
The key bit here is the
Expand|Select|Wrap|Line Numbers
  1. oMail.Attachments.Add strWorkPath & rsFiles!tx_PdfFile, olByValue
Using that several times you can in theory add quite alot of attachments. That said, you will probably hit the limit of how large emails your provider allows to send, or the receiver is allowed to receive.

The olByValue means that a copy of the object is being added to the email, after which you can delete the original object, even if the email isn't send yet. If you don't include this, I BELIEVE that the copy of the object isn't actually done until you call the SEND. In the code I displayed the email is displayed for the user, for the user to confirm, and manually click the send button.

To place it into the outbox immediately replace
Expand|Select|Wrap|Line Numbers
  1. oMail.Display
with
Expand|Select|Wrap|Line Numbers
  1. oMail.Send
Aug 29 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: mary | last post by:
I am developing an Access db which will be used by multiple users. My questions are: Does MS Access have problems with multiple users accessing the db at once? If yes, what is your solution...
1
by: intl04 | last post by:
Are there any problems with multiple user access to the same Access database on a shared network drive? I have 'shared' chosen for 'default open mode'. As for the record locking properties, I...
7
by: Mega1 | last post by:
is this possable to send more than 1 report in one email
0
by: CountDraculla | last post by:
Fixing Multiple Database bug in adoDB popular data access layer for php, adoDB can support multiple databases from different provider at time, but not from same provider. what I mean is if you...
2
by: judelakmal | last post by:
I have an application written in vb 6.0 application. It connects multiple MS Access databases sometimes. I would like to know is will this effects the performance of the application.
35
by: ttamilvanan81 | last post by:
Hai, am using the Email function with Attachments in Vb and Access Forms. The Emial function is working. Then how to attach the file with my mail. there is any Browse control is there. anybody...
34
by: majahops via WebmasterKB.com | last post by:
When I click "save" after adding a new record (which contains, among other fields, the person's email address), I want an email to automatically be sent to that person (at the email that is in the...
1
by: Jyo | last post by:
Hi All! I have problem regarding multiple file attachment. Can any one help regarding script like gmail provides for attach a file with remove link ? Also please note that this code should...
6
by: yimma216 | last post by:
Hi there. I am looking for a way to generate a report from a web form and attached it to an email so that I could send it. The form is retrieving data from a Microsoft SQL server and display...
2
by: cooksc | last post by:
I have an Access database where I want to send a PDF file as an attachment. I have code that sends the basic email from Access through LotusNotes and it works well. What I would like help on is:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.