Solved

Send email attachment using VB?

Posted on 2003-10-29
5
1,401 Views
Last Modified: 2010-05-01
Hi. I have a piece of code that sends an email via Outlook:

Private Sub SendEmail(strProblem)

On Error GoTo errEmail

Dim objSession      As Object
Dim objMessage      As Object
Dim objRecipient    As Object
Dim strProblemFull  As String
Dim nRow            As Integer
Dim strProfileInfo  As String
Dim strMailbox      As String
Dim sSubject        As String
Dim objMsg          As Object
Dim sFrom           As String

   
   For nRow = 1 To nEmails
       
        sTemp = ""
        ' get list of emails for the report type and group
        lRet = GetPrivateProfileString("Email", "Subject", "", sTemp, Len(sTemp), sINI)
        'Set the properties of the message object
        sSubject = Replace(Trim$(sTemp), Chr(0), "")
       
        sTemp = ""
        ' get list of emails for the report type and group
        lRet = GetPrivateProfileString("Email", "from", "", sTemp, Len(sTemp), sINI)
        'Set the properties of the message object
        sFrom = Replace(Trim$(sTemp), Chr(0), "")
       
        sTemp = ""
        ' get list of emails for the report type and group
        lRet = GetPrivateProfileString("Email", "To" & CStr(nRow), "", sTemp, Len(sTemp), sINI)
       
        Set objMsg = CreateObject("CDO.Message")
        objMsg.From = sFrom
        objMsg.To = Replace(Trim$(sTemp), Chr(0), "")
        objMsg.Subject = sSubject
        objMsg.TextBody = strProblem
        objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "abzexmb1"
        objMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
        objMsg.Configuration.Fields.Update
        objMsg.Send
        Set objMsg = Nothing

    Next
       
     
Exit Sub

The details for the email (to, from etc) are held in an ini file:
[email]

noofEmails=1
frequency=7
subject=
from=
to1=

This works fine but I want to be able to send an attachment along with the email (access db). Does anyone know how to do this?

Thanks.

0
Comment
Question by:Mhairijm
  • 3
  • 2
5 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9642695
you could use this exelent a free component:
http://www.freevbcode.com/ShowCode.Asp?ID=109
0
 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 200 total points
ID: 9642714
Also, there is an .Attachment collection if i rememeber well in Outlook
0
 

Author Comment

by:Mhairijm
ID: 9642748
Thanks. I'll have a look and let you know how I get on.
0
 

Author Comment

by:Mhairijm
ID: 9643427
.Attachment works a treat, thanks!
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 9643624
Glad to help.
Thanks for "A" grade.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2003, my txt file export is running backwards 4 51
Adding to a VBA? 6 69
vb6 connector to mongodb 2 81
Exit a vb6 apps when a calling it apps closes 15 46
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question