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)) = "MailItem" 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 "All Email Has Been Imported"
Else
MsgBox "There Is No Email To Be Imported"
End If
End Function
Any Help Would Be Much Appreciated
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)) = "MailItem" 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 "All Email Has Been Imported"
Else
MsgBox "There Is No Email To Be Imported"
End If
End Function
Any Help Would Be Much Appreciated