VBA to Outlook problem
I am attempting to connect to Outlook through Access VBA and I'm receiving a Type MisMatch Error Run-Time Error 13.
Here's my code. It's funny, it worked perfectly fine. Now it stops on the 'Next' in my loop.
Function importWAMU() As Boolean
'check if an email was received.
Dim objApp As Outlook.Application
Dim objns As Outlook.NameSpace
Dim objfolder As Outlook.MAPIFolder
Dim objitem As Outlook.MailItem
Dim newDate As String
Set objApp = CreateObject("Outlook.Application")
Set objns = objApp.GetNamespace("MAPI")
Set objfolder = objns.GetDefaultFolder(olFolderInbox) 'looks in Inbox for email
For Each objitem In objfolder.Items
objApp.ActiveExplorer.WindowState = 1 'Minimize Outlook window
newDate = CStr(Format(Date - 1, "m/d"))
If objitem.SenderName = "Lindsay, Derek" Then 'Email From
If objitem.Subject Like "*" & newDate & "*" Then 'Subject line
'found email
importWAMU = True
'export email body to .txt file
objitem.SaveAs "R:\Research and Technology\Derek\WAMUEmail.txt", olTXT
objApp.ActiveExplorer.WindowState = 1 'Minimize Outlook window
End If
End If
Next 'Here's the runtime Error!
Set objApp = Nothing
Set objitem = Nothing
ImportWAMUTextFile
DoCmd.SetWarnings False
DoCmd.OpenQuery "UpdateWAMUeMail2BQD"
DoCmd.SetWarnings True
End Function
|