problems with .SaveAs during recursive enumeration in public folders

  • Thread starter Peter van den Hooff
  • Start date
P

Peter van den Hooff

Hi

As experienced VBA-programmer in ms-access I try to do something in
outlook but do not exactly know the right approach.

Situation: outlook 2003 and exchange and ms-access

Objectives:
1) create structure public folders as windows folders ( done = OK)
2) get mail content in ms-access tables (linked tables to exchange/
mapilevel) (done=OK)
3) save attachments as in created windows folders ( done=OK)
4) save items as *.MSG (?? works only certain mails, reason
unknown ???)
From within ms-access I enumerate recursive folders in folders.

The following code is from line XX in a recursive folders in folders
enumeration:

? 1 : what is the difference between olMailItem and olPostItem (Said
before access programmer, not outlook
? 2 : why can't i set MyOutlookMailItem = objMapiSubFolder.Items(i)
but do I have to use
MyUndefindeObject = objMapiSubFolder.Items(i)

Advice is appreciated (please don't bother for the dutch name in the
code:


THANKS Peter van den Hooff
'----------------------------------------------------------------------------------------------------------------------------

onwards line XX in ap_FoldersInFolder objMapiSubFolder
----
----
----
ap_LogFolderStructuur nivo, prepad, objMapiSubFolder.Name,
objMapiSubFolder.DefaultItemType

prepad = prepad & "\" & objMapiSubFolder.Name

'-- mkdir to save attachments
ap_maakpad prepad, "C:\"

If objMapiSubFolder.DefaultItemType = 6 And volgnr0 = 1
(MAPIlevel0 public folders) Then
i = objMapiSubFolder.Items.Count
If i > 0 Then
Teller = Teller + 1
For i = 1 To objMapiSubFolder.Items.Count
'-- objItem = object,
'-- objItem = OUTLOOK.MAILITEM does not work
Set objItem = objMapiSubFolder.Items(i)
sGUID = objItem.EntryID
j = objItem.Attachments.Count
If j > 0 Then
For j = 1 To objItem.Attachments.Count
Set myAttachment =
objItem.Attachments.Item(j)
Set o = myAttachment.Parent
If o.Class = olMail Then
Set myMailItem = o
On Error GoTo FoutBijSaveAs
'-- WORKS ONLY FOR ABOU 20% OF THE
MAILS ?????????????????????????
myMailItem.SaveAs "c:\" & prepad &
"\" & DatumTijdMail & "_" & myMailItem.SenderEmailAddress & ".msg",
olMSG
On Error GoTo Foutafhandeling
Set myMailItem = Nothing
End If
myAttachment.SaveAsFile "c:\" & prepad &
"\" & myAttachment.FileName
sSQL = "INSERT INTO tbl_attachments " & _
"([EntryID],[folder],[file],
[datumtijdmail]) " & _
" values (""" & sGUID & """,""" & prepad &
""",""" & myAttachment.FileName & """,""" & DatumTijdMail & """)"
CurrentDb.Execute sSQL
SysCmd acSysCmdSetStatus, "c:\" & prepad &
"\" & myAttachment.FileName
Next j
End If
Next i
End If
End If

ap_FoldersInFolder objMapiSubFolder

Next objMapiSubFolder
 
E

Eric Legault [MVP - Outlook]

olMailItem is equal to an e-mail message form ("IPM.Note") and the MailItem
object, while olPostItem is a Post form ("IPM.Post") and equivalent to the
PostItem object.

An e-mail folder can contain both Mail and Post items, so when you are
looping through a collection you need to use a generic Object variable when
you do "For Each myVar", or check the Object.Class value to see which
olItemType value it equates before you cast the item to a particular Outlook
object.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:
http://www.collaborativeinnovations.ca
Blog: http://blogs.officezealot.com/legault/


Peter van den Hooff said:
Hi

As experienced VBA-programmer in ms-access I try to do something in
outlook but do not exactly know the right approach.

Situation: outlook 2003 and exchange and ms-access

Objectives:
1) create structure public folders as windows folders ( done = OK)
2) get mail content in ms-access tables (linked tables to exchange/
mapilevel) (done=OK)
3) save attachments as in created windows folders ( done=OK)
4) save items as *.MSG (?? works only certain mails, reason
unknown ???)
From within ms-access I enumerate recursive folders in folders.

The following code is from line XX in a recursive folders in folders
enumeration:

? 1 : what is the difference between olMailItem and olPostItem (Said
before access programmer, not outlook
? 2 : why can't i set MyOutlookMailItem = objMapiSubFolder.Items(i)
but do I have to use
MyUndefindeObject = objMapiSubFolder.Items(i)

Advice is appreciated (please don't bother for the dutch name in the
code:


THANKS Peter van den Hooff
'----------------------------------------------------------------------------------------------------------------------------

onwards line XX in ap_FoldersInFolder objMapiSubFolder
----
----
----
ap_LogFolderStructuur nivo, prepad, objMapiSubFolder.Name,
objMapiSubFolder.DefaultItemType

prepad = prepad & "\" & objMapiSubFolder.Name

'-- mkdir to save attachments
ap_maakpad prepad, "C:\"

If objMapiSubFolder.DefaultItemType = 6 And volgnr0 = 1
(MAPIlevel0 public folders) Then
i = objMapiSubFolder.Items.Count
If i > 0 Then
Teller = Teller + 1
For i = 1 To objMapiSubFolder.Items.Count
'-- objItem = object,
'-- objItem = OUTLOOK.MAILITEM does not work
Set objItem = objMapiSubFolder.Items(i)
sGUID = objItem.EntryID
j = objItem.Attachments.Count
If j > 0 Then
For j = 1 To objItem.Attachments.Count
Set myAttachment =
objItem.Attachments.Item(j)
Set o = myAttachment.Parent
If o.Class = olMail Then
Set myMailItem = o
On Error GoTo FoutBijSaveAs
'-- WORKS ONLY FOR ABOU 20% OF THE
MAILS ?????????????????????????
myMailItem.SaveAs "c:\" & prepad &
"\" & DatumTijdMail & "_" & myMailItem.SenderEmailAddress & ".msg",
olMSG
On Error GoTo Foutafhandeling
Set myMailItem = Nothing
End If
myAttachment.SaveAsFile "c:\" & prepad &
"\" & myAttachment.FileName
sSQL = "INSERT INTO tbl_attachments " & _
"([EntryID],[folder],[file],
[datumtijdmail]) " & _
" values (""" & sGUID & """,""" & prepad &
""",""" & myAttachment.FileName & """,""" & DatumTijdMail & """)"
CurrentDb.Execute sSQL
SysCmd acSysCmdSetStatus, "c:\" & prepad &
"\" & myAttachment.FileName
Next j
End If
Next i
End If
End If

ap_FoldersInFolder objMapiSubFolder

Next objMapiSubFolder
 
P

Peter van den Hooff

olMailItem is equal to an e-mail message form ("IPM.Note") and the MailItem
object, while olPostItem is a Post form ("IPM.Post") and equivalent to the
PostItem object.

An e-mail folder can contain both Mail and Post items, so when you are
looping through a collection you need to use a generic Object variable when
you do "For Each myVar", or check the Object.Class value to see which
olItemType value it equates before you cast the item to a particular Outlook
object.

--
Eric Legault (Outlook MVP, MCDBA, MCTS: Messaging & Collaboration)
Try Picture Attachments Wizard for Outlook:http://www.collaborativeinnovations.ca
Blog:http://blogs.officezealot.com/legault/

Peter van den Hooff said:
As experienced VBA-programmer in ms-access I try to do something in
outlook but do not exactly know the right approach.
Situation: outlook 2003 and exchange and ms-access
Objectives:
1) create structure public folders as windows folders ( done = OK)
2) get mail content in ms-access tables (linked tables to exchange/
mapilevel) (done=OK)
3) save attachments as in created windows folders ( done=OK)
4) save items as *.MSG (?? works only certain mails, reason
unknown ???)
The following code is from line XX in a recursive folders in folders
enumeration:
? 1 : what is the difference between olMailItem and olPostItem (Said
before access programmer, not outlook
? 2 : why can't i set MyOutlookMailItem = objMapiSubFolder.Items(i)
but do I have to use
MyUndefindeObject = objMapiSubFolder.Items(i)
Advice is appreciated (please don't bother for the dutch name in the
code:
THANKS Peter van den Hooff
'----------------------------------------------------------------------------------------------------------------------------
onwards line XX in ap_FoldersInFolder objMapiSubFolder
----
prepad = prepad & "\" & objMapiSubFolder.Name
'-- mkdir to save attachments
ap_maakpad prepad, "C:\"
If objMapiSubFolder.DefaultItemType = 6 And volgnr0 = 1
(MAPIlevel0 public folders) Then
i = objMapiSubFolder.Items.Count
If i > 0 Then
Teller = Teller + 1
For i = 1 To objMapiSubFolder.Items.Count
'-- objItem = object,
'-- objItem = OUTLOOK.MAILITEM does not work
Set objItem = objMapiSubFolder.Items(i)
sGUID = objItem.EntryID
j = objItem.Attachments.Count
If j > 0 Then
For j = 1 To objItem.Attachments.Count
Set myAttachment =
objItem.Attachments.Item(j)
Set o = myAttachment.Parent
If o.Class = olMail Then
Set myMailItem = o
On Error GoTo FoutBijSaveAs
'-- WORKS ONLY FOR ABOU 20% OF THE
MAILS ?????????????????????????
myMailItem.SaveAs "c:\" & prepad &
"\" & DatumTijdMail & "_" & myMailItem.SenderEmailAddress & ".msg",
olMSG
On Error GoTo Foutafhandeling
Set myMailItem = Nothing
End If
myAttachment.SaveAsFile "c:\" & prepad &
"\" & myAttachment.FileName
sSQL = "INSERT INTO tbl_attachments " & _
"([EntryID],[folder],[file],
[datumtijdmail]) " & _
" values (""" & sGUID & """,""" & prepad &
""",""" & myAttachment.FileName & """,""" & DatumTijdMail & """)"
CurrentDb.Execute sSQL
SysCmd acSysCmdSetStatus, "c:\" & prepad &
"\" & myAttachment.FileName
Next j
End If
Next i
End If
End If
ap_FoldersInFolder objMapiSubFolder
Next objMapiSubFolder

Thanks,

When will an item in my Inbox be an 'mailItem' and when a 'postItem'?
Probably a basic question but as along as i don't raise the question i
will remain ignorant

Peter
 
M

Michael Bauer [MVP - Outlook]

A PostItem is a message in a Public Folder that is not sent as an e-mail.

Is that you cannot handle PostItems in your code the issue you're asking
for? That could look like this:

Dim obj as Object
Dim Items as Outlook.Items
Set Atts as Outlook.Attachments
Dim i&, y&

Set Items=objMapiSubFolder.Items
For i=1 To Items.Count
Set obj=Items(i)
Select Case True
Case (TypeOf obj Is Outlook.MailItem), (TypeOf obj is Outlook.PostItem)
obj.SaveAs 'Path', olMSG
Set Atts=obj.Attachments
For y=1 atts.Count
Atts(y).SaveAsFile 'Path'
Next
end select
Next

--
Viele Gruesse / Best regards
Michael Bauer - MVP Outlook
Quick-Cats - The most effective way to assign Outlook categories:
http://www.shareit.com/product.html?productid=300120654&languageid=1
(German: http://www.VBOffice.net/product.html?pub=6)


Am 3 Apr 2007 10:33:13 -0700 schrieb Peter van den Hooff:
Hi

As experienced VBA-programmer in ms-access I try to do something in
outlook but do not exactly know the right approach.

Situation: outlook 2003 and exchange and ms-access

Objectives:
1) create structure public folders as windows folders ( done = OK)
2) get mail content in ms-access tables (linked tables to exchange/
mapilevel) (done=OK)
3) save attachments as in created windows folders ( done=OK)
4) save items as *.MSG (?? works only certain mails, reason
unknown ???)
From within ms-access I enumerate recursive folders in folders.

The following code is from line XX in a recursive folders in folders
enumeration:

? 1 : what is the difference between olMailItem and olPostItem (Said
before access programmer, not outlook
? 2 : why can't i set MyOutlookMailItem = objMapiSubFolder.Items(i)
but do I have to use
MyUndefindeObject = objMapiSubFolder.Items(i)

Advice is appreciated (please don't bother for the dutch name in the
code:


THANKS Peter van den Hooff
'----------------------------------------------------------------------------------------------------------------------------

onwards line XX in ap_FoldersInFolder objMapiSubFolder
----
----
----
ap_LogFolderStructuur nivo, prepad, objMapiSubFolder.Name,
objMapiSubFolder.DefaultItemType

prepad = prepad & "\" & objMapiSubFolder.Name

'-- mkdir to save attachments
ap_maakpad prepad, "C:\"

If objMapiSubFolder.DefaultItemType = 6 And volgnr0 = 1
(MAPIlevel0 public folders) Then
i = objMapiSubFolder.Items.Count
If i > 0 Then
Teller = Teller + 1
For i = 1 To objMapiSubFolder.Items.Count
'-- objItem = object,
'-- objItem = OUTLOOK.MAILITEM does not work
Set objItem = objMapiSubFolder.Items(i)
sGUID = objItem.EntryID
j = objItem.Attachments.Count
If j > 0 Then
For j = 1 To objItem.Attachments.Count
Set myAttachment =
objItem.Attachments.Item(j)
Set o = myAttachment.Parent
If o.Class = olMail Then
Set myMailItem = o
On Error GoTo FoutBijSaveAs
'-- WORKS ONLY FOR ABOU 20% OF THE
MAILS ?????????????????????????
myMailItem.SaveAs "c:\" & prepad &
"\" & DatumTijdMail & "_" & myMailItem.SenderEmailAddress & ".msg",
olMSG
On Error GoTo Foutafhandeling
Set myMailItem = Nothing
End If
myAttachment.SaveAsFile "c:\" & prepad &
"\" & myAttachment.FileName
sSQL = "INSERT INTO tbl_attachments " & _
"([EntryID],[folder],[file],
[datumtijdmail]) " & _
" values (""" & sGUID & """,""" & prepad &
""",""" & myAttachment.FileName & """,""" & DatumTijdMail & """)"
CurrentDb.Execute sSQL
SysCmd acSysCmdSetStatus, "c:\" & prepad &
"\" & myAttachment.FileName
Next j
End If
Next i
End If
End If

ap_FoldersInFolder objMapiSubFolder

Next objMapiSubFolder
 

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