Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Attachments

Status
Not open for further replies.

GaryDw

MIS
Oct 3, 2001
7
US
Hi

I am writing out sent emails to a 3rd party application and have run into a problem with attachments. When I write out the attachment's filename, I cannot find the path of the attachment anywhere. Does anyone know where the path is stored, or how I can best handle the attachments.

Thanks in advance for your help

Gary
 
Try this solution.

Above is a functions that you can use to Send Mail with attachement´s. You will need the InitializeOutlook() in order to work. Dont forget to set your Variables as Public if you will need them as Public Variables and to Turn On Microsoft Outlook in your References.


Function CreateMail(astrRecip As Variant, _
strSubject As String, _
strMessage As String, _
Optional astrAttachments As Variant) As Boolean
' This procedure illustrates how to create a new mail message
' and use the information passed as arguments to set message
' properties for the subject, text (Body property), attachments,
' and recipients.

Dim objNewMail As Outlook.MailItem
Dim varRecip As Variant
Dim varAttach As Variant
Dim blnResolveSuccess As Boolean

On Error GoTo CreateMail_Err

' Use the InitializeOutlook procedure to initialize global
' Application and NameSpace object variables, if necessary.
If golApp Is Nothing Then
If InitializeOutlook = False Then
MsgBox "Unable to initialize Outlook Application " _
& "or NameSpace object variables!"
Exit Function
End If
End If

Set golApp = New Outlook.Application
Set objNewMail = golApp.CreateItem(olMailItem)
With objNewMail
For Each varRecip In astrRecip
.Recipients.Add varRecip
Next varRecip
blnResolveSuccess = .Recipients.ResolveAll
For Each varAttach In astrAttachments
.Attachments.Add varAttach
Next varAttach
.Subject = strSubject
.Body = strMessage
If blnResolveSuccess Then
.Send
Else
MsgBox "Unable to resolve all recipients. Please check " _
& "the names."
.Display
End If
End With

CreateMail = True

CreateMail_End:
Exit Function
CreateMail_Err:
CreateMail = False
Resume CreateMail_End
End Function

---

Function InitializeOutlook() As Boolean
' This function is used to initialize the global Application and
' NameSpace variables.

On Error GoTo Init_Err

Set golApp = New Outlook.Application ' Application object.
Set gnspNameSpace = golApp.GetNamespace("MAPI") ' Namespace object.

InitializeOutlook = True

Init_End:
Exit Function
Init_Err:
InitializeOutlook = False
Resume Init_End
End Function Best Regards

---
JoaoTL
mail@jtl.co.pt
MS Access Site: The Page: moved to
 
Thank you for the response.

Howver, the problem I am having has to do with once the email has been sent. I am using the Send event to write the content of the email (to, cc, subject, body and attachments) to a 3rd party application. For the attachments, there does not appear to be a path and therefore from my 3rd party app, it will not be able to locate the attachment. So for example, if I am entering an email message and I attach a file named test.txt which is located in a folder/directory named c:\temp, I want to pass to my 3rd party application "c:\temp\test.txt"

Any ideas?

Thanks
Gary
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top