Read Outlook items to Access

  • Thread starter Thread starter Lasse
  • Start date Start date
L

Lasse

Hi,
Please help me.

This code works in Windows 2000, but not in VISTA.
(I use Office 2003)

They sends an Outlook form with a lot of fields, to a mailbox.
From Access I read out the data and add it to a table.
I use this code to check if there is any new Mail with Subject: 'Buy Back
Request' in the Mailbox.

If I restart Outlook and the database, it only can find the first item. On
all the others I get an
error 'Type Mismatch' because it cant get any information from 'myItem'
(cant find 'Subject').
Sometimes when I only have restarted the database I get this Error at the
first item.

What's the differences between Win2K and VISTA?

'------------------------------------------------------
Function Count_New_Mail()
On Error GoTo Err_Count_New_Mail

Dim myolApp As New Outlook.Application
Dim myNamespace As Outlook.NameSpace
Dim myMailbox As Outlook.MAPIFolder
Dim myItems As Outlook.Items
Dim myItem As Outlook.MailItem
Dim CountNo As Integer
Dim MailboxName As String

MailboxName = DLookup("[tbl_params.MailboxName]", "[tbl_params]",
"[tbl_params.MailboxName] <> ''")

Set myNamespace = myolApp.GetNamespace("MAPI")
Set myMailbox = myNamespace.Folders(MailboxName)
Set myMailbox = myMailbox.Folders("Inbox")
Set myItems = myMailbox.Items

Set myItem = myItems.Find("[subject] = 'Buy Back Request'")
' Problem at the first Item
While TypeName(myItem) <> "Nothing"
If TypeName(myItem.UserProperties.Find("BBstatus")) <> "Nothing"
Then
CountNo = CountNo + 1
End If
Set myItem = myItems.FindNext ' Problem at the
secound Item
Wend

Exit_Count_New_Mail:

Count_New_Mail = CountNo
DoCmd.Hourglass (False)
Set myNamespace = Nothing
Set myMailbox = Nothing
Set myMailbox = Nothing
Set myItems = Nothing

Exit Function

Err_Count_New_Mail:

DoCmd.Hourglass (False)
MsgBox Err.Description
Resume Exit_Count_New_Mail

End Function

'-----------------------------------------------------------
 
Lasse,

This is not related to macros in Access. I suggest you re-post your
question to the externaldata newsgroup, where you are more likely to get
good help.
 
Back
Top