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

Import Multi Line Email From Outlook

Status
Not open for further replies.

BenSC

Technical User
Jul 24, 2001
43
GB
Hi All,
What I am trying to do is import an email containing name and address details from Outlook into Access. The problem is that if the email text has a carriage return in it then access only copies up to that point and doesn't copy the rest of the message. Therefore, I can copy an address formatted as follows:
line 1, line 2, line 3, line 4

but only the first line of this email would be copied.

line 1
line 2
etc

The code I'm using is:

Function ImportEmail()

' Set up DAO objects (uses existing "tblInbox" table)
Dim rst As Recordset
Dim db As Database

Set db = CurrentDb()
Set rst = db.OpenRecordset("tblInbox")

' Set up Outlook objects.
Dim Outlook As New Outlook.Application
Dim OutlookNS As Outlook.NameSpace
Dim cf As Outlook.MapiFolder
Dim c As Outlook.MailItem
Dim objItems As Outlook.Items
Dim Prop As Outlook.UserProperty
Dim iNumContacts As Integer
Dim i As Integer

Set OutlookNS = Outlook.GetNamespace("MAPI")
Set cf = OutlookNS.GetDefaultFolder(olFolderInbox)
Set objItems = cf.Items
iNumContacts = objItems.Count
If iNumContacts <> 0 Then
For i = 1 To iNumContacts
If TypeName(objItems(i)) = &quot;MailItem&quot; Then
Set c = objItems(i)
rst.AddNew
rst!To = c.To
rst!From = c.SenderName
rst!Subject = c.Subject
rst!Message = c.Body
rst!Received = c.ReceivedTime
rst.Update
End If
Next i
rst.Close
MsgBox &quot;All Email Has Been Imported&quot;
Else
MsgBox &quot;There Is No Email To Be Imported&quot;
End If

End Function

Any Help Would Be Much Appreciated
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top