Outlook97 - Access97 Reading Mail Items in inbox 
Author Message
 Outlook97 - Access97 Reading Mail Items in inbox

I am attempting to extract data the body of a series of
Emails.

Incomming EMails are located (unsurprisingly) in the
inbox, I want to interate through them and read the body
of each Email, from Access97 via vba.

I have made the Access97/Outlook97 connection and worked
my way partway thru the resulting objects, how do I get to
the InBox folder, and then to the Mail items?

Code so far is:

    Dim olApp As Outlook.Application
    Dim olNS As Outlook.NameSpace
    Dim olMail As MailItem
    Dim olFolder As Outlook.MAPIFolder
    Dim olFlds As Outlook.Folders
    Dim i As Integer
    '
    On Error GoTo Error_MailItems
    Set olApp = GetObject("Outlook.Application")
    Set olNS = olApp.GetNamespace("MAPI")
    olNS.Logon
    Set olFlds = olNS.Folders("Personal Folders").Folders

Thanks in advance

Ken Reay



Sat, 03 Apr 2004 19:56:15 GMT  
 Outlook97 - Access97 Reading Mail Items in inbox
You're on the right track. To get the Inbox, use the
Namespace.GetDefaultFolder method:

    Set olFolder = olNS.GetDefaultFolder(olFolderInbox)    ' 6

To work with the items in the Inbox, use a For Each loop:

    For Each objItem in olFolder.Items
        ' so something with objItem
    Next

You cannot assume that every objItem is a MailItem. Test the .Class property
before using any MailItem-specific properties or methods.

See http://www.slipstick.com/dev/vb.htm for more basic Outlook code.

--
Sue Mosher, Outlook MVP
   Outlook and Exchange Solutions
   at http://www.slipstick.com


Quote:
> I am attempting to extract data the body of a series of
> Emails.

> Incomming EMails are located (unsurprisingly) in the
> inbox, I want to interate through them and read the body
> of each Email, from Access97 via vba.

> I have made the Access97/Outlook97 connection and worked
> my way partway thru the resulting objects, how do I get to
> the InBox folder, and then to the Mail items?

> Code so far is:

>     Dim olApp As Outlook.Application
>     Dim olNS As Outlook.NameSpace
>     Dim olMail As MailItem
>     Dim olFolder As Outlook.MAPIFolder
>     Dim olFlds As Outlook.Folders
>     Dim i As Integer
>     '
>     On Error GoTo Error_MailItems
>     Set olApp = GetObject("Outlook.Application")
>     Set olNS = olApp.GetNamespace("MAPI")
>     olNS.Logon
>     Set olFlds = olNS.Folders("Personal Folders").Folders

> Thanks in advance

> Ken Reay



Sat, 03 Apr 2004 20:33:30 GMT  
 Outlook97 - Access97 Reading Mail Items in inbox
 Thanks Sue

With your assistance I have moved on a step.

But now I am getting Error 438 Object does not support...

on the line  'If objItem.Class = olMailItem ' below

Do I need to define objItem more explicitly (ie as an
Outlook type?)

  Dim olApp As Outlook.Application
    Dim olNS As Outlook.NameSpace
    Dim olMail As MailItem
    Dim olFolder As Outlook.MAPIFolder
    Dim olFlds As Outlook.Folders
    Dim i As Integer
    Dim olItems As Outlook.Items
    Dim objItem As Object
    '
    On Error GoTo Error_MailItems
    Set olApp = GetObject("Outlook.Application")
    Set olNS = olApp.GetNamespace("MAPI")
    olNS.Logon
    Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
    For Each objItem In olFolder.Items
        If objItem.Class = olMailItem Then

        End If

    Next

Quote:
>-----Original Message-----
>You're on the right track. To get the Inbox, use the
>Namespace.GetDefaultFolder method:

>    Set olFolder = olNS.GetDefaultFolder

(olFolderInbox)    ' 6
Quote:

>To work with the items in the Inbox, use a For Each loop:

>    For Each objItem in olFolder.Items
>        ' so something with objItem
>    Next

>You cannot assume that every objItem is a MailItem. Test
the .Class property
>before using any MailItem-specific properties or methods.

>See http://www.slipstick.com/dev/vb.htm for more basic
Outlook code.

>--
>Sue Mosher, Outlook MVP
>   Outlook and Exchange Solutions
>   at http://www.slipstick.com



>> I am attempting to extract data the body of a series of
>> Emails.

>> Incomming EMails are located (unsurprisingly) in the
>> inbox, I want to interate through them and read the body
>> of each Email, from Access97 via vba.

>> I have made the Access97/Outlook97 connection and worked
>> my way partway thru the resulting objects, how do I get
to
>> the InBox folder, and then to the Mail items?

>> Code so far is:

>>     Dim olApp As Outlook.Application
>>     Dim olNS As Outlook.NameSpace
>>     Dim olMail As MailItem
>>     Dim olFolder As Outlook.MAPIFolder
>>     Dim olFlds As Outlook.Folders
>>     Dim i As Integer
>>     '
>>     On Error GoTo Error_MailItems
>>     Set olApp = GetObject("Outlook.Application")
>>     Set olNS = olApp.GetNamespace("MAPI")
>>     olNS.Logon
>>     Set olFlds = olNS.Folders("Personal
Folders").Folders

>> Thanks in advance

>> Ken Reay

>.



Sat, 03 Apr 2004 21:24:13 GMT  
 Outlook97 - Access97 Reading Mail Items in inbox
You should always Dim the variable used for items in an Outlook folder as
Object, not as a specific item type. Why? The Inbox can contain other types
of items -- meeting requests, NDRs, task requests.

I just looked up the Outlook 97 object model (which you can do yourself in
the VBA object browser), and it doesn't support the Class property. I think
you can use the TypeName() function instead.


Quote:
> Thanks Sue

> With your assistance I have moved on a step.

> But now I am getting Error 438 Object does not support...

> on the line  'If objItem.Class = olMailItem ' below

> Do I need to define objItem more explicitly (ie as an
> Outlook type?)

>   Dim olApp As Outlook.Application
>     Dim olNS As Outlook.NameSpace
>     Dim olMail As MailItem
>     Dim olFolder As Outlook.MAPIFolder
>     Dim olFlds As Outlook.Folders
>     Dim i As Integer
>     Dim olItems As Outlook.Items
>     Dim objItem As Object
>     '
>     On Error GoTo Error_MailItems
>     Set olApp = GetObject("Outlook.Application")
>     Set olNS = olApp.GetNamespace("MAPI")
>     olNS.Logon
>     Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
>     For Each objItem In olFolder.Items
>         If objItem.Class = olMailItem Then

>         End If

>     Next
> >-----Original Message-----
> >You're on the right track. To get the Inbox, use the
> >Namespace.GetDefaultFolder method:

> >    Set olFolder = olNS.GetDefaultFolder
> (olFolderInbox)    ' 6

> >To work with the items in the Inbox, use a For Each loop:

> >    For Each objItem in olFolder.Items
> >        ' so something with objItem
> >    Next

> >You cannot assume that every objItem is a MailItem. Test
> the .Class property
> >before using any MailItem-specific properties or methods.

> >See http://www.slipstick.com/dev/vb.htm for more basic
> Outlook code.

> >--
> >Sue Mosher, Outlook MVP
> >   Outlook and Exchange Solutions
> >   at http://www.slipstick.com



> >> I am attempting to extract data the body of a series of
> >> Emails.

> >> Incomming EMails are located (unsurprisingly) in the
> >> inbox, I want to interate through them and read the body
> >> of each Email, from Access97 via vba.

> >> I have made the Access97/Outlook97 connection and worked
> >> my way partway thru the resulting objects, how do I get
> to
> >> the InBox folder, and then to the Mail items?

> >> Code so far is:

> >>     Dim olApp As Outlook.Application
> >>     Dim olNS As Outlook.NameSpace
> >>     Dim olMail As MailItem
> >>     Dim olFolder As Outlook.MAPIFolder
> >>     Dim olFlds As Outlook.Folders
> >>     Dim i As Integer
> >>     '
> >>     On Error GoTo Error_MailItems
> >>     Set olApp = GetObject("Outlook.Application")
> >>     Set olNS = olApp.GetNamespace("MAPI")
> >>     olNS.Logon
> >>     Set olFlds = olNS.Folders("Personal
> Folders").Folders

> >> Thanks in advance

> >> Ken Reay

> >.



Sat, 03 Apr 2004 21:49:42 GMT  
 Outlook97 - Access97 Reading Mail Items in inbox
Thanks again Sue, I am at office at present and Outlook
VBA help is not installed, hence my questions, it takes
fore-ever to get IT support to do anything here, so I was
just being impatient to get on, I can look it up when I
get home where I have neccessary help files on my home PC

Thanks again for your help.

Regards

Ken Reay

Quote:
>-----Original Message-----
>You should always Dim the variable used for items in an
Outlook folder as
>Object, not as a specific item type. Why? The Inbox can
contain other types
>of items -- meeting requests, NDRs, task requests.

>I just looked up the Outlook 97 object model (which you
can do yourself in
>the VBA object browser), and it doesn't support the Class
property. I think
>you can use the TypeName() function instead.



>> Thanks Sue

>> With your assistance I have moved on a step.

>> But now I am getting Error 438 Object does not
support...

>> on the line  'If objItem.Class = olMailItem ' below

>> Do I need to define objItem more explicitly (ie as an
>> Outlook type?)

>>   Dim olApp As Outlook.Application
>>     Dim olNS As Outlook.NameSpace
>>     Dim olMail As MailItem
>>     Dim olFolder As Outlook.MAPIFolder
>>     Dim olFlds As Outlook.Folders
>>     Dim i As Integer
>>     Dim olItems As Outlook.Items
>>     Dim objItem As Object
>>     '
>>     On Error GoTo Error_MailItems
>>     Set olApp = GetObject("Outlook.Application")
>>     Set olNS = olApp.GetNamespace("MAPI")
>>     olNS.Logon
>>     Set olFolder = olNS.GetDefaultFolder(olFolderInbox)
>>     For Each objItem In olFolder.Items
>>         If objItem.Class = olMailItem Then

>>         End If

>>     Next
>> >-----Original Message-----
>> >You're on the right track. To get the Inbox, use the
>> >Namespace.GetDefaultFolder method:

>> >    Set olFolder = olNS.GetDefaultFolder
>> (olFolderInbox)    ' 6

>> >To work with the items in the Inbox, use a For Each
loop:

>> >    For Each objItem in olFolder.Items
>> >        ' so something with objItem
>> >    Next

>> >You cannot assume that every objItem is a MailItem.
Test
>> the .Class property
>> >before using any MailItem-specific properties or
methods.

>> >See http://www.slipstick.com/dev/vb.htm for more basic
>> Outlook code.

>> >--
>> >Sue Mosher, Outlook MVP
>> >   Outlook and Exchange Solutions
>> >   at http://www.slipstick.com



>> >> I am attempting to extract data the body of a series
of
>> >> Emails.

>> >> Incomming EMails are located (unsurprisingly) in the
>> >> inbox, I want to interate through them and read the
body
>> >> of each Email, from Access97 via vba.

>> >> I have made the Access97/Outlook97 connection and
worked
>> >> my way partway thru the resulting objects, how do I
get
>> to
>> >> the InBox folder, and then to the Mail items?

>> >> Code so far is:

>> >>     Dim olApp As Outlook.Application
>> >>     Dim olNS As Outlook.NameSpace
>> >>     Dim olMail As MailItem
>> >>     Dim olFolder As Outlook.MAPIFolder
>> >>     Dim olFlds As Outlook.Folders
>> >>     Dim i As Integer
>> >>     '
>> >>     On Error GoTo Error_MailItems
>> >>     Set olApp = GetObject("Outlook.Application")
>> >>     Set olNS = olApp.GetNamespace("MAPI")
>> >>     olNS.Logon
>> >>     Set olFlds = olNS.Folders("Personal
>> Folders").Folders

>> >> Thanks in advance

>> >> Ken Reay

>> >.

>.



Sat, 03 Apr 2004 22:19:04 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Solution: Reading Outlook97 Inbox

2. Read Outlook97 Inbox

3. Setting Inbox to process mail items

4. Missed New Mail/Inbox Items Add Events

5. Reading mail from another user's inbox

6. TransferSpreadsheet from Outlook97 mailitem to Access97 table using Access DAO

7. Access97 to Outlook97 Calendar

8. Connecting Access97 to Outlook97?

9. Sending Internet Mail via Outlook97/2000 or Express

10. OUTLOOK97 mail detection

11. Solution: Reading Outlook97 Attachments

12. Reading Outlook97 - Attachments.

 

 
Powered by phpBB® Forum Software