Hi All, I had been playing about with some code in Outlook to export emails details to Access. For testing I had changed the code to export from a sub folder with a small sample set of emails that worked no problems. But when I changed it to work on the Inbox it fails after exporting about a quarter of 17,083 I get the
Run-time error ‘13’: Type Mismatch which fails on Next.
I can understand Type mismatch normally being Datetime values being put into wrong field types etc but it did work before on the small sample?
Help
Run-time error ‘13’: Type Mismatch which fails on Next.
I can understand Type mismatch normally being Datetime values being put into wrong field types etc but it did work before on the small sample?
Help
Code:
Public Sub ExportInbox()
Dim oApp As Outlook.Application
Dim oAccess As Access.Application
Dim wrkAccess As Workspace
Dim MyDB As DAO.Database
Dim oInbox As Outlook.MAPIFolder
Dim oInboxItems As Outlook.Items
Dim oMail As Outlook.MailItem
Dim rst As DAO.Recordset
Set oApp = New Outlook.Application
Set oInbox = oApp.GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
Set oInboxItems = oInbox.Items
Set oAccess = New Access.Application
'Create Microsoft Access Workspace and Database Objects
Set wrkAccess = oAccess.DBEngine.CreateWorkspace("", "admin", "", dbUseJet)
Set MyDB = wrkAccess.OpenDatabase("C:\Test\Test.accdb", True)
Set rst = MyDB.OpenRecordset("tblEMails", dbOpenDynaset)
For Each oMail In oInboxItems
With rst
.AddNew
![ImportedEntryID] = oMail.EntryID
![ImportedFromEmailAddress] = oMail.SenderEmailAddress
![ImportedSenderName] = oMail.SenderName
![ImportedTo] = oMail.To
![ImportedCC] = oMail.CC
![ImportedBCC] = oMail.BCC
![ImportedSubject] = oMail.Subject
![ImportedBody] = oMail.Body
![ImportedBodyHTML] = oMail.HTMLBody
![ImportedReceivedStamp] = oMail.ReceivedTime
.Update
End With
Next `<-- Fails here
'oApp.Quit
oAccess.Quit
rst.Close
Set oApp = Nothing
Set oAccess = Nothing
Set rst = Nothing
End Sub