I've been trying to find a way to import outlook emails to access through vba.
Every code sample I've encountered has something like ...GetNamespace("MAPI")
I can't get past this, I keep getting an error:
Run-time error'91':
Object variable or with block variable not set
Can anybody help with this?
Below is the entire code i've attached to a command button
Code:
Dim olApp As Outlook.Application
Dim olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim eFldr As Outlook.MAPIFolder
Set oldapp = olApp.GetNamespace("MAPI")
Set eFldr = olNS.Folders("ASM")
For Each olamil In eFldr.Items
DoCmd.RunSQL "INSERT INTO ASM(subject) " _
& "SELECT " & olMail.Subject
Next
Set olApp = Nothing
Set olNS = Nothing
Set olMail = Nothing
Set olMail = Nothing
Set eFldr = Nothing