VB6 - Email attachment not working

Reply

Join Date: Jul 2007
Posts: 113
Reputation: tgifgemini is an unknown quantity at this point 
Solved Threads: 0
tgifgemini tgifgemini is offline Offline
Junior Poster

VB6 - Email attachment not working

 
0
  #1
Jul 20th, 2007
VB6 - Email attachment not working
Hi,
I wrote this program to send email through VB. The email is working okay but the attachment I need to attach to the email is not being attached.

See my codes below:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Set OutlookApp = CreateObject("Outlook.Application")
  2. Set OutlookMail = OutlookApp.CreateItem(0)
  3. Set NSpace = OutlookApp.GetNamespace("MAPI")
  4. Set OutlookContacts = NSpace.GetDefaultFolder _(olFolderContacts).Items
  5.  
  6. MailAttach = "C:\ProjectStatus.xls" <-- This spreadsheet resides in my hard drive.
  7.  
  8. OutlookMail.To = EmailID
  9. OutlookMail.Subject = "Project Status"
  10. OutlookMail.Body = "This is VB email test"
  11.  
  12. If Len(MailAttach) = 0 Then
  13. OutlookMail.Attachments.Add MailAttach '"C:\ProjectStatus.xls"
  14. End If
  15.  
  16. 'OutlookMail.Display 'To display the email
  17. OutlookMail.Send 'To send the email
  18.  
  19. Set OutlookApp = Nothing
  20. Set OutlookMail = Nothing

Any assistance will be appreciated.
tgifgemini
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 848
Reputation: QVeen72 is on a distinguished road 
Solved Threads: 120
QVeen72's Avatar
QVeen72 QVeen72 is offline Offline
Practically a Posting Shark

Re: VB6 - Email attachment not working

 
0
  #2
Jul 21st, 2007
Hi,

along with the above code, Create a seperate Attacmnet object, check this code:

Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim OAttach As Outlook.Attachment
  2. If Not IsMissing(MailAttach) Then
  3. Set OAttach = OutLookMail.Attachments.Add(MailAttach)
  4. End If


Regards
Veena
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 113
Reputation: tgifgemini is an unknown quantity at this point 
Solved Threads: 0
tgifgemini tgifgemini is offline Offline
Junior Poster

Re: VB6 - Email attachment not working

 
0
  #3
Jul 23rd, 2007
Thanks for your expertise. My attachment is working now. However, I have one minor problem. See my follow-up post regarding RT Error: 424 object required.
My code bummed out on this line:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. lvw.ListItems.Add , , OutlookAddressEntry.Name
Thanks again,
tgifgemini.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 113
Reputation: tgifgemini is an unknown quantity at this point 
Solved Threads: 0
tgifgemini tgifgemini is offline Offline
Junior Poster

Re: VB6 - Runtime error 424 - Object required (Outlook email set up)

 
0
  #4
Jul 23rd, 2007
In my perception, I have dimensioned the object below, but have not set it; To what should I set it?
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
  1. Dim OutlookAddressEntry As Outlook.AddressEntry
  2.  
  3. Set OutlookAddressEntry = ????????????? <== This maybe my problem

You can see all the previous code you gave me.
tgifgemini.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Visual Basic 4 / 5 / 6 Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC