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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Saving attachment location to Access table - filepath object?

Status
Not open for further replies.

RMcCallan

Programmer
Sep 20, 2010
62
GB
I have some code which saves emails into a database, creates new folders for new senders etc etc but what I now want to do is when a new email comes in, i want any attachments to be saved into a table (by saving the location and then having the ability to go back in and open it from that location)... All I really need is the code which will show the filepath... does anybody know how to do this?

I currently have the below code which saved the email body, subject, time/date etc into my table tbl002_SupportRequest.

Code:
rstSupportRequest.AddNew
                strRequestID = rstSupportRequest!RequestID
                rstSupportRequest!emailaddress = MailObject.SenderEmailAddress
                rstSupportRequest!Subject = MailObject.Subject
                rstSupportRequest!Request = MailObject.Body
                Debug.Print MailObject.Body
                rstSupportRequest!RequestDate = MailObject.ReceivedTime
                Debug.Print strRequestID

I want to be able to save the attachment location into tbl003_Attachments in a similar way... hopefully by passing in the path using a recordset, my problem is that I can't refer to the file path... I have tried using attachment.pathname but can't get it to work... apparently it must be a linked file but I'm not too sure what making it a linked file entails...

Any replies appreciated.

Thanks,
Rebecca
 
Set objFolder = objSession.Inbox
dim filenam as string
' Get message collection of the inbox
Set objMessages = objSession.Inbox.Messages

' Get first message of inbox
Set objMessage = objMessages.Item(1)

' Loop through the attachments collection

For Each objAttachment In objMessage.Attachments

' Extract all attachments to the filesystem
strAttachName = objAttachment.Name

filenam="c:\Somefolder\" & strAttachName
objAttachment.WriteToFile(filenam)

-> insert code here to insert the attachment name into the database

Currentproject.connection.execute "INSERT '"+filenam+"' blah blah


Next


 
Oh, the above assumes you have references declared to CDO
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top