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
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