Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Email Attachment Problem 1

Status
Not open for further replies.

rnegde

Technical User
Jan 13, 2002
23
US
First of all, I'm no access guru, but hopefully there's one here that help me with this because I have hit the wall. In my database, I have code that pulls data and populates both an Excel and Word templates and save them as one of the fields of data. These files are automaticly saved in the same directory and they are never n amed the same (that field is unique). I have the following code that opens Outlook and will send an email with the specified file attached and it works just fine, BUT, I need to be able to attach multiple files to the email. I can't specify the inidividual file names because they will always be different. An Input Msg Box would not be that good because the user will never remember all the files names by the time the email needs to be sent, so they would have to look in the folder and if they did that they could just highlight and send to. I want to do this at the push of the command button. What I need it to do is attach all that are in the folder to the email (something like *.* in DOS). The number of files will be different any time the command button is pushed, might be 5, might be 15. So far I haven't figured how to tell it to attach any and all files that are in C:\temp.
Here is the code...if anyone has any ideas, I would greatly appreciate it. And, if this is something that is just NOT doable in access, then please tell me that to so I can give it up without feeling like it beat me!! :)
Thanks much!!!
Private Sub SendEmailButton_Click()
On Error GoTo Err_SendEmailButton_Click

Dim objOutlook As Object
Dim objMessage As Object
Dim BodyString As String
Dim SubjectString As String

SubjectString = "Excel File"
'BodyString is the text you would like to send
'SubjectString is what you would like to appear as the Subject
'Attachments if you want to attach an item
'Recipients = e-mail address of the recipient.

Set objOutlook = CreateObject("Outlook.Application")
Set objMessage = objOutlook.CreateItem(0) 'olMailItem

With objMessage
.Subject = SubjectString
.Body = "Here are your files"
.Attachments.Add "C:\temp\test.xls", , 2880
' Here is where I need to tell it "all files"
.Recipients.Add "them@there.com"
.Send
End With
'End If
objOutlook.Quit


Exit_SendEmailButton_Click:
Exit Sub

Err_SendEmailButton_Click:
MsgBox Err.Description
Resume Exit_SendEmailButton_Click

End Sub
 
[tt]
dim sFile as string

With objMessage
.Subject = SubjectString
.Body = "Here are your files"

sFile=dir("C:\Temp\*.*")
do while sFile<>&quot;&quot;
.Attachments.Add &quot;C:\temp\&quot; & sFile, , 2880
sFile=dir
loop


.Recipients.Add &quot;them@there.com&quot;
.Send
End With

[/tt]
 
Thanks Justin! That works like a charm. I figured that the *.* should work somehow, but I never could get the rest of the syntax right. I appreciate the help!
Will this system let me vote for you more that once!! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top