Update question

  • Thread starter Thread starter George Hester
  • Start date Start date
G

George Hester

I have this in ThisOutlookSession

Private WithEvents olInboxItems As Items
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
End Sub

Now I can get the subject of New mail received by Item.Subject

But if I try to Update a received e-mail say I want to remove the attachements out of it I need to use this:

Item.Update

, but when I do that I get an error "This method is not supported. or recognized" (something like that).

Can I change the ByVal Item as Object to say:

ByVal Item As Outlook.MailItem

so that I can use intellisense in the Sub AND still have this work correctly? I believe then I would be able to use the method Upadate then. As it stands now I cannot. Thanks.
 
Update is a method of the CDO Message object, not Outlook items. Use Item.Save instead.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

I have this in ThisOutlookSession

Private WithEvents olInboxItems As Items
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
End Sub

Now I can get the subject of New mail received by Item.Subject

But if I try to Update a received e-mail say I want to remove the attachements out of it I need to use this:

Item.Update

, but when I do that I get an error "This method is not supported. or recognized" (something like that).

Can I change the ByVal Item as Object to say:

ByVal Item As Outlook.MailItem

so that I can use intellisense in the Sub AND still have this work correctly? I believe then I would be able to use the method Upadate then. As it stands now I cannot. Thanks.
 
Thanks Sue. I am having a problem with this. It is not getting all the attachements. I think I know why but my tests so far haven't really changed anything. Here's what I have:

For Each objAtt In Item.Attachments
'MsgBox "In Attachment check"
intPos = InStrRev(objAtt.FileName, ".")
If intPos > 0 Then
objAtt.SaveAsFile ("C:\hold\attachments\" & objAtt.FileName)
objAtt.Delete
Item.Save
End If
Next
'Item.Save
MsgBox IsEmpty(Item.Attachments)
iMessageBox = MsgBox("Stop here", vbOKCancel)
If iMessageBox <> 1 Then
GoTo finish1
End If

So since not all the attachments are getting stripped out I figured Item.Attachments was not not empty. So I would have just had the for loop run again if IsEmpty(Item.Attachments) was False. But that won't work because it seems all items IsEmpty(Item.Attachements) is False.

I believe the trouble is the Item.Attachements is not updating correctly when we remove a member of it. Is that right and do you know of way we can flush that so it finally does become empty?. I know then the For Each witll throw an error when Item.Attachments is empty but I can always check for that I suppose.

--
George Hester
__________________________________
Update is a method of the CDO Message object, not Outlook items. Use Item.Save instead.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

I have this in ThisOutlookSession

Private WithEvents olInboxItems As Items
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
End Sub

Now I can get the subject of New mail received by Item.Subject

But if I try to Update a received e-mail say I want to remove the attachements out of it I need to use this:

Item.Update

, but when I do that I get an error "This method is not supported. or recognized" (something like that).

Can I change the ByVal Item as Object to say:

ByVal Item As Outlook.MailItem

so that I can use intellisense in the Sub AND still have this work correctly? I believe then I would be able to use the method Upadate then. As it stands now I cannot. Thanks.
 
Never use Delete in a For Each loop. The index is reset after each deletion, so you'll delete only every other item. Instead use a countdown loop:

For I = Item.Attachments.Count to 1 Step -1
Set objAtt = Item.Attachments(I)
' do stuff with objAtt
Next

or a While loop:

While Item.Attachments.Count > 0
Set objAtt = Item.Attachments(1)
' do stuff with objAtt
Loop

You also need an Item.Save in there somewhere.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

Thanks Sue. I am having a problem with this. It is not getting all the attachements. I think I know why but my tests so far haven't really changed anything. Here's what I have:

For Each objAtt In Item.Attachments
'MsgBox "In Attachment check"
intPos = InStrRev(objAtt.FileName, ".")
If intPos > 0 Then
objAtt.SaveAsFile ("C:\hold\attachments\" & objAtt.FileName)
objAtt.Delete
Item.Save
End If
Next
'Item.Save
MsgBox IsEmpty(Item.Attachments)
iMessageBox = MsgBox("Stop here", vbOKCancel)
If iMessageBox <> 1 Then
GoTo finish1
End If

So since not all the attachments are getting stripped out I figured Item.Attachments was not not empty. So I would have just had the for loop run again if IsEmpty(Item.Attachments) was False. But that won't work because it seems all items IsEmpty(Item.Attachements) is False.

I believe the trouble is the Item.Attachements is not updating correctly when we remove a member of it. Is that right and do you know of way we can flush that so it finally does become empty?. I know then the For Each witll throw an error when Item.Attachments is empty but I can always check for that I suppose.

--
George Hester
__________________________________
Update is a method of the CDO Message object, not Outlook items. Use Item.Save instead.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

I have this in ThisOutlookSession

Private WithEvents olInboxItems As Items
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
End Sub

Now I can get the subject of New mail received by Item.Subject

But if I try to Update a received e-mail say I want to remove the attachements out of it I need to use this:

Item.Update

, but when I do that I get an error "This method is not supported. or recognized" (something like that).

Can I change the ByVal Item as Object to say:

ByVal Item As Outlook.MailItem

so that I can use intellisense in the Sub AND still have this work correctly? I believe then I would be able to use the method Upadate then. As it stands now I cannot. Thanks.
 
OK Sue I got it. I needed to use a backwards loop as explained at Ken's site:

http://www.slovaktech.com/code_samples.htm#StripAttachments

--
George Hester
__________________________________
Thanks Sue. I am having a problem with this. It is not getting all the attachements. I think I know why but my tests so far haven't really changed anything. Here's what I have:

For Each objAtt In Item.Attachments
'MsgBox "In Attachment check"
intPos = InStrRev(objAtt.FileName, ".")
If intPos > 0 Then
objAtt.SaveAsFile ("C:\hold\attachments\" & objAtt.FileName)
objAtt.Delete
Item.Save
End If
Next
'Item.Save
MsgBox IsEmpty(Item.Attachments)
iMessageBox = MsgBox("Stop here", vbOKCancel)
If iMessageBox <> 1 Then
GoTo finish1
End If

So since not all the attachments are getting stripped out I figured Item.Attachments was not not empty. So I would have just had the for loop run again if IsEmpty(Item.Attachments) was False. But that won't work because it seems all items IsEmpty(Item.Attachements) is False.

I believe the trouble is the Item.Attachements is not updating correctly when we remove a member of it. Is that right and do you know of way we can flush that so it finally does become empty?. I know then the For Each witll throw an error when Item.Attachments is empty but I can always check for that I suppose.

--
George Hester
__________________________________
Update is a method of the CDO Message object, not Outlook items. Use Item.Save instead.
--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

I have this in ThisOutlookSession

Private WithEvents olInboxItems As Items
Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
End Sub

Now I can get the subject of New mail received by Item.Subject

But if I try to Update a received e-mail say I want to remove the attachements out of it I need to use this:

Item.Update

, but when I do that I get an error "This method is not supported. or recognized" (something like that).

Can I change the ByVal Item as Object to say:

ByVal Item As Outlook.MailItem

so that I can use intellisense in the Sub AND still have this work correctly? I believe then I would be able to use the method Upadate then. As it stands now I cannot. Thanks.
 
Back
Top