oxicottin
Learning by pecking away....
- Local time
- Today, 18:15
- Joined
- Jun 26, 2007
- Messages
- 856
Hello, I already can get the pdf as a report but cant seem to attach multi images if there is any. The way im doing it now is DoCmd.SendObject acReport which I cant find anything on the web about multi attachments. I did however find using outlook and creating a collection and it works running a test in my DB except I have two issues.
1. The WHERE of my statement is creating a Run-time error '3061' Too few parameters Expected 1. But if I get rid of the WHERE it runs fine.
2. I have a table that saves the folder and file name then I use a function GetCurrentPath() to get the path of where the folder and files are. The below part of the code gathers the full path of each image separated by a ; and in a long row which debug.print shows.
Now the original code found showed I had to use .add for each path which that way does work like show in the code.
'colFiles.Add "C:\Users\Bla\Desktop\Accident & Safety Database 6-15-20\\Images\31.jpg"
'colFiles.Add "C:\Users\Bla\Desktop\Accident & Safety Database 6-15-20\\Images\34.jpg"
'colFiles.Add "C:\Users\Bla\Desktop\Accident & Safety Database 6-15-20\\Images\35.jpg"
BUT instead im trying to loop through and create a list that can be added using colFiles.Add sImageList as shown in the full code but that isn't working. How can I loop through and colFiles.Add like it does when individually?
1. The WHERE of my statement is creating a Run-time error '3061' Too few parameters Expected 1. But if I get rid of the WHERE it runs fine.
2. I have a table that saves the folder and file name then I use a function GetCurrentPath() to get the path of where the folder and files are. The below part of the code gathers the full path of each image separated by a ; and in a long row which debug.print shows.
Code:
With rs
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
sImageList = GetCurrentPath() & .Fields("ImagePath")
.MoveNext
End If
If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
sImageList = sImageList & "; " & GetCurrentPath() & .Fields("ImagePath")
.MoveNext
Loop
End If
.Close
End With
Now the original code found showed I had to use .add for each path which that way does work like show in the code.
'colFiles.Add "C:\Users\Bla\Desktop\Accident & Safety Database 6-15-20\\Images\31.jpg"
'colFiles.Add "C:\Users\Bla\Desktop\Accident & Safety Database 6-15-20\\Images\34.jpg"
'colFiles.Add "C:\Users\Bla\Desktop\Accident & Safety Database 6-15-20\\Images\35.jpg"
BUT instead im trying to loop through and create a list that can be added using colFiles.Add sImageList as shown in the full code but that isn't working. How can I loop through and colFiles.Add like it does when individually?
Code:
Public Sub testEmail()
Dim vTo, vSubj, vBody
Dim colFiles As New Collection
Dim db As DAO.Database
Dim rs As DAO.Recordset
Dim sImageList As String
vTo = "MrWiley.com"
vSubj = "test multi attachs"
vBody = "Dear Wiley"
Set db = CurrentDb()
Set rs = db.OpenRecordset("SELECT tbl_AccidentImages.ImagePath " & _
"FROM tbl_AccidentImages " & _
"WHERE (((tbl_AccidentImages.AccidentID)=[Forms]![frm_AccidentIllnessEntry]![txtAccidentID]));")
With rs
If (Not .BOF) And (Not .EOF) Then
.MoveFirst
sImageList = GetCurrentPath() & .Fields("ImagePath")
.MoveNext
End If
If (Not .BOF) And (Not .EOF) Then
Do Until .EOF
sImageList = sImageList & "; " & GetCurrentPath() & .Fields("ImagePath")
.MoveNext
Loop
End If
.Close
End With
[/code
colFiles.Add sImageList
'colFiles.Add "C:\Users\Bla\Desktop\Accident & Safety Database 6-15-20\\Accident_Images\31.jpg"
'colFiles.Add "C:\Users\Bla\Desktop\Accident & Safety Database 6-15-20\\Accident_Images\34.jpg"
'colFiles.Add "C:\Users\Bla\Desktop\Accident & Safety Database 6-15-20\\Accident_Images\35.jpg"
Call Send1Email(vTo, vSubj, vBody, colFiles)
Set colFiles = Nothing
End Sub
Public Function Send1Email(ByVal pvTo, ByVal pvSubj, ByVal pvBody, Optional pcolFiles As Collection) As Boolean
Dim oApp As Outlook.Application
Dim oMail As Outlook.MailItem
Dim vFile As Variant
Set oApp = CreateObject("Outlook.Application")
Set oMail = oApp.CreateItem(olMailItem)
With oMail
.To = pvTo
.Subject = pvSubj
.Body = pvBody
If Not IsEmpty(pcolFiles) Then
For Each vFile In pcolFiles
Debug.Print vFile
Stop
.Attachments.Add vFile, olByValue, 1
Next
End If
.Send
End With
Send1Email = True
Set oMail = Nothing
Set oApp = Nothing
End Function