Retrieving e-mail from Outlook doesn't work on Public Folder

J

jdpeterson

Hello,

The code below works pefectly on my own inbox, but dies on Pubic Folders.
VBA says the Mailobject does not support the "To" property, but only when I
access mail in Public Folders.

Dim TempRst As DAO.Recordset
Dim rst As DAO.Recordset
Dim olapp As Outlook.Application
Dim Inbox As Outlook.MAPIFolder
Dim InboxItems As Outlook.Items
Dim Mailobject As Object 'Outlook.MailItem 'Object
Dim db As DAO.Database
Dim dealer As Integer


DoCmd.RunSQL "Delete * from EMail_temp"
Set db = CurrentDb

Set olapp = CreateObject("Outlook.Application")
Set Inbox = olapp.GetNamespace("MAPI").PickFolder

Set TempRst = CurrentDb.OpenRecordset("EMail_temp")

Set InboxItems = Inbox.Items

Inbox.Display

For Each Mailobject In InboxItems

If Mailobject.UnRead Then

With TempRst

.AddNew
!Subject = Mailobject.Subject
!From = Mailobject.SenderName
!Body = Mailobject.Body
!Received = Mailobject.SentOn
!To = Mailobject.To
.Update
Mailobject.UnRead = False

End With
End If
Next
MsgBox "Done"
Set olapp = Nothing
Set Inbox = Nothing
Set InboxItems = Nothing
Set Mailobject = Nothing
Set TempRst = Nothing
 
D

David C. Holley

Try posting in microsoft.public.outlook.program_vba newsgroup. Although
you're automating Outlook via Access, its still Outlook that you're working
with.

I was thinking that you can place MailItems in a Public Folder but this
article would suggest that it has to be done as an attachment to a PostItem.

http://msdn.microsoft.com/en-us/library/aa210983(office.11).aspx

You may have to add some logic that detects if you're sending an email or
making a post and then use the correct object (MailItem or PostItem),
however the very odd part is that the general purpose OBJECT should work.
See what the other newsgroup has to say.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top