\r\n\r\n
Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Communications > Attach multiple files to an email


\r\n \r\n
 
 
Thread Tools Display Modes

\r\n\r\n\r\n
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??
\r\n
\r\nI 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.
\r\n
\r\nAnyone have any ideas to help me? Anything is greatly appreciated.
\r\n
\r\nThanks,
\r\nBen
\r\n
\r\n-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-
\r\nTHE CODE
\r\n-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-' + '-
\r\n
\r\nMe.txtDateSubmited = Format(Now(), "DD-MMM-YY")
\r\n
\r\nDim objOutlook As Object
\r\nDim objSession As Object
\r\nDim objMessage As Object
\r\nDim objRecipient As Object
\r\nDim Attachment As String
\r\nDim Address As String
\r\nDim AttachmnetName As String
\r\nDim cerDIR As String
\r\nDim cerFile As String
\r\n
\r\ncerDIR = Me.txtCERNum
\r\ncerFile = Me.txtCERNum & ".txt"
\r\n
\r\n
\r\nWith CD3
\r\n .DialogTitle = "Attach Files"
\r\n .CancelError = False
\r\n .ShowOpen
\r\n .InitDir = "I:\\CERs\\123456\\"
\r\n If Len(.FileName) = 0 Then
\r\n Exit Sub
\r\n End If
\r\n AttachmentName = .FileName
\r\n End With
\r\n
\r\nAttachment1 = "I:\\CERs\\" & cerDIR & "\\" & cerFile
\r\nAttachment2 = AttachmentName
\r\nAddress = "me@myaddress.com"
\r\n
\r\nSet objOutlook = CreateObject("Outlook.Application")
\r\nSet objSession = objOutlook.GetNameSpace("MAPI")
\r\nSet objMessage = objOutlook.CreateItem(olMailItem)
\r\nSet objRecipient = objSession.CreateRecipient(Address)
\r\n
\r\nobjSession.Logon
\r\nobjMessage.recipients.Add (objRecipient)
\r\nobjMessage.subject = "TEST"
\r\nobjMessage.Body = "This is a test"
\r\nobjMessage.attachments.Add (Attachment1)
\r\nobjMessage.attachments.Add (Attachment2)
\r\nobjMessage.Send
\r\nMsgBox "message sent successfully"
\r\nSet objRecipient = Nothing
\r\nobjSession.Logoff
\r\n \r\n\r\n
\r\n \r\n\r\n \r\n \r\n\r\n \r\n\r\n \r\n\r\n \r\n\r\n
\r\n \r\n \r\n \r\n \r\n Reply With Quote\r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n \r\n
\r\n\r\n \r\n\r\n
\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n \r\n \r\n \r\n \r\n\r\n\r\n\r\n\r\n'; // next/previous post info pn[370162] = "370162,370162"; pn[0] = ",370162"; // cached usernames pu[0] = guestphrase; pu[32251] = "Pathseeker"; // -->
Prev Previous Post   Next Post Next
  #1  
Old 04-22-2003, 10:07 AM
Pathseeker Pathseeker is offline
Newcomer
 
Join Date: Mar 2003
Location: Edmonton, Alberta, Canada
Posts: 13
Question 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
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Open Multiple Files in Excel RDH Excel 1 07-21-2003 03:46 PM
Opening Multiple Files at Once ... really test your troubleshooting skillz :( Audax321 General 0 11-13-2002 06:52 PM
Copying multiple files using SHFILEOPSTRUCT paulcat General 1 10-12-2001 03:18 PM
Required files burningodzilla General 11 09-12-2001 04:51 PM
ShellExecute with multiple files skubik General 2 04-25-2001 03:28 AM

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->