04-22-2003, 10:07 AM
Join Date: Mar 2003
Location: Edmonton, Alberta, Canada
Attach multiple files to an email
I am using the code bellow to successfully attach to and email two documents, one which is automatically attached and the other which the user chooses to attach and then it sends the email. However I want the user to be able to select multiple files to the email and the number will always vary depending on how many files the user need to attach. The common dialog box I am using won't allow the user to select more than one file and then the message sends. Does anyone know how I can allow the user to select more than one file at a time?? Or some better way of setting up my code so this can happen??
I was thinking maybe there needs to be something in my code which will count the number of files in the cerDIR folder and loop the attach code that many times so they can keep adding one at a time, but I very new to VB programming and I am not sure how to use a count and loop code or where to place it in the code.
Anyone have any ideas to help me? Anything is greatly appreciated.
Me.txtDateSubmited = Format(Now(), "DD-MMM-YY")
Dim objOutlook As Object
Dim objSession As Object
Dim objMessage As Object
Dim objRecipient As Object
Dim Attachment As String
Dim Address As String
Dim AttachmnetName As String
Dim cerDIR As String
Dim cerFile As String
cerDIR = Me.txtCERNum
cerFile = Me.txtCERNum & ".txt"
.DialogTitle = "Attach Files"
.CancelError = False
.InitDir = "I:\CERs\123456\"
If Len(.FileName) = 0 Then
AttachmentName = .FileName
Attachment1 = "I:\CERs\" & cerDIR & "\" & cerFile
Attachment2 = AttachmentName
Address = "firstname.lastname@example.org"
Set objOutlook = CreateObject("Outlook.Application")
Set objSession = objOutlook.GetNameSpace("MAPI")
Set objMessage = objOutlook.CreateItem(olMailItem)
Set objRecipient = objSession.CreateRecipient(Address)
objMessage.subject = "TEST"
objMessage.Body = "This is a test"
MsgBox "message sent successfully"
Set objRecipient = Nothing