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

Importing Attachement File Name From Outlook 2007 to Access 2007

Status
Not open for further replies.

Accel45

Technical User
Jul 7, 2004
83
US
I am using the code below to import information from one selected email in Outlook into Access. The code works.

The code allows me to highlight an email in Outlook then using a command button in Access the email infomation is pulled into Access. The code does not retrieve attachment information.

What I need help with is modifying the code to also retrieve any attachment file names into a text box on the form like the other email information.

Any help would be appreciated.

Thank you

Code:
Dim objApp As Outlook.Application
    Dim objItem As Outlook.MailItem
    Dim SndName As String, SndAddr As String, ToName As String, CCName As String
    Dim Subj As String, Rcvd As String, MsgBody As String, AtchName As String
    Dim Atch As Outlook.Attachment
    Set objApp = New Outlook.Application
    For Each objItem In objApp.ActiveExplorer.Selection
        If objItem.Class = olMail Then
            With objItem
                SndName = .SenderName
                SndAddr = .SenderEmailAddress
                ToName = .To
                CCName = .CC
                Subj = .Subject
                MsgBody = .Body
                Rcvd = .ReceivedTime
            
            End With
            
        End If
    Next
   
Me.txtMsgBody = MsgBody
Me.txtSndName = SndName
Me.txtSndAddr = SndAddr
Me.txtTONAME = ToName
Me.txtCCName = CCName
Me.txtSubj = Subj
Me.txtRcvd = Rcvd


 Set objItem = Nothing
    Set objApp = Nothing
 
Well, the problem you will run into is multiple attachments, if you're just wanting it in a textbox or single field.

If you're wanting to permanently store the information in Access, it'd be best to have a sturcture like:

TableMessages (MessageID, to, From, Subject, body, otherfields)
TableAttachments(AttachID, MessageID, AttachmentName, anything else)

Then in your code, you'd simply loop through the attachments, and add a new record to the Attachments table for each attachment.

Then to see that on the form, you could have a listbox or combo box or subform list out all the related attachments.

"But thanks be to God, which giveth us the victory through our Lord Jesus Christ." 1 Corinthians 15:57
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top