johnsm1981
Registered User.
- Local time
- Today, 00:52
- Joined
- Feb 20, 2015
- Messages
- 14
hi - please can someone correct this code. I am scraping an outlook email into access.
i can see it is doing that part successfully in the debug.print (immediate) window.
i just cant seem to add the recordset to the database file (rst.AddNew)
it is failing on "Do until EOF()" i've tried various code, when i cut this part out it then fails at "rst.AddNew" with a Runtime 91 - Object variable or With Block not set
thanks in advance!
Sub getEmails()
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.NameSpace
Dim k
Dim j
Dim x
Dim xXx
Dim olFolder As Outlook.MAPIFolder
Dim lngCol As Long
Dim olItem As Object
Dim whichAccount As String
Dim objNS As Outlook.NameSpace
Dim BodyTxt As String
Dim BodyRow As String
Dim db As Database
Dim rst As Recordset
Dim strData As String
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set objNS = olApp.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox).Folders("MarkDrafts")
'table in access is called Email, field to update is called EmailData
For Each msg In olFolder.Items
Debug.Print msg.Body
BodyTxt = msg.Body
Do Until EOF() 'failing here "compile - argument not optional"
rst.AddNew 'failing here when i remove "until EOF" from above line
rst!EmailData = strData
rst.Update
Loop
Next
rst.Close
Set olApp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing
End Sub
i can see it is doing that part successfully in the debug.print (immediate) window.
i just cant seem to add the recordset to the database file (rst.AddNew)
it is failing on "Do until EOF()" i've tried various code, when i cut this part out it then fails at "rst.AddNew" with a Runtime 91 - Object variable or With Block not set
thanks in advance!
Sub getEmails()
Dim olApp As Outlook.Application
Dim olNamespace As Outlook.NameSpace
Dim k
Dim j
Dim x
Dim xXx
Dim olFolder As Outlook.MAPIFolder
Dim lngCol As Long
Dim olItem As Object
Dim whichAccount As String
Dim objNS As Outlook.NameSpace
Dim BodyTxt As String
Dim BodyRow As String
Dim db As Database
Dim rst As Recordset
Dim strData As String
Set olApp = New Outlook.Application
Set olNamespace = olApp.GetNamespace("MAPI")
Set objNS = olApp.GetNamespace("MAPI")
Set olFolder = objNS.GetDefaultFolder(olFolderInbox).Folders("MarkDrafts")
'table in access is called Email, field to update is called EmailData
For Each msg In olFolder.Items
Debug.Print msg.Body
BodyTxt = msg.Body
Do Until EOF() 'failing here "compile - argument not optional"
rst.AddNew 'failing here when i remove "until EOF" from above line
rst!EmailData = strData
rst.Update
Loop
Next
rst.Close
Set olApp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing
End Sub