Wrox Programmer Forums
|
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 12th, 2007, 03:04 PM
Registered User
 
Join Date: Jun 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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






Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA in excel and outlook dlindamood2000 Excel VBA 19 December 7th, 2006 10:16 AM
E-mail using VBA and Outlook cc16 Access VBA 6 December 4th, 2006 11:07 AM
VBA Excel, outlook createobject Willie Johnson Jr Excel VBA 0 March 10th, 2006 05:11 AM
Need help starting Outlook w/ VBA ArtDecade VB How-To 0 August 26th, 2004 11:09 AM
Receiving mail with Outlook 2000 VBA spotts-71 Pro VB 6 7 July 17th, 2003 03:04 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.