Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Send email attachment using VB?

Posted on 2003-10-29
5
Medium Priority
?
1,407 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 800 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

596 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