
04-22-2003, 10:07 AM
|
|
Newcomer
|
|
Join Date: Mar 2003
Location: Edmonton, Alberta, Canada
Posts: 13
|
|
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.
Thanks,
Ben
---------------------------
THE CODE
---------------------------
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"
With CD3
.DialogTitle = "Attach Files"
.CancelError = False
.ShowOpen
.InitDir = "I:\CERs\123456\"
If Len(.FileName) = 0 Then
Exit Sub
End If
AttachmentName = .FileName
End With
Attachment1 = "I:\CERs\" & cerDIR & "\" & cerFile
Attachment2 = AttachmentName
Address = "me@myaddress.com"
Set objOutlook = CreateObject("Outlook.Application")
Set objSession = objOutlook.GetNameSpace("MAPI")
Set objMessage = objOutlook.CreateItem(olMailItem)
Set objRecipient = objSession.CreateRecipient(Address)
objSession.Logon
objMessage.recipients.Add (objRecipient)
objMessage.subject = "TEST"
objMessage.Body = "This is a test"
objMessage.attachments.Add (Attachment1)
objMessage.attachments.Add (Attachment2)
objMessage.Send
MsgBox "message sent successfully"
Set objRecipient = Nothing
objSession.Logoff
|
|