Save changes bug - Any known workarounds ?

  • Thread starter Thread starter Vic Eldridge
  • Start date Start date
V

Vic Eldridge

Hi People,

I'm using the following code to produce a new MailItem in my Drafts folder.

-------------------------------------------------
Sub CreateNewEmailInDraftsFolder()
Dim objMailItem As Outlook.MailItem
Set objMailItem = Application.CreateItem(olMailItem)
With objMailItem
.To = "(e-mail address removed)"
.Subject = "Not happy Billy..."
.Body = "Dear Bill, your boy's bugs are driving me batty."
.Attachments.Add ("C:\SomeBugs4U2.exe")
.Close (olSave)
End With
Set objMailItem = Nothing
End Sub
-------------------------------------------------

This is working good except for one thing. If I navigate to my Drafts folder
and open the newly created MailItem by double-clicking on it, then I close it
without making any changes, Outlook 2003 asks if I want to save changes.
This is wrong - there were no changes made.

I've noticed that if I comment out the Attachments.Add line, everything works
as it should. But that doesn't help me much, as the app I'm working on must
have attachments.

I've also noticed that if I include the .Display method somewhere inside the
With...End With block, then everything works as it should. This however, is
not a satisfactory solution as it causes flashing on the screen as multiple
MailItems are generated.

The code seems fine to me. Is there some other trick I'm missing ?
Could someone at least confirm whether or not they see the same problem on
their system ?



Regards,
Vic Eldridge
 
Hi Vic,

for the moment I´ve no OL 2003 installed. So I´ve to guess. What
happens, if you are calling especially the save method before closing
the item? I`m using close only if there is an Inspector to close.
Another way could be using CDO instead of the OOM.
 
Thanks for your reply Michael.

I've already tried the Save method instead of Close(olSave). There was
no difference in the outcome.

You mentioned you don't have Outlook 2003. Does that mean you don't see
the same problem in previous versions ?

I'm still stuck on this problem. I thought I'd cracked it by Saving the
MailItem from inside the NewInspector event, but that rearranges the
order in which the MailItems are sorted, which again is an undesirable
side-effect.

I'm fine with VBA but I'm new to the OOM. As for CDO, I don't even know
what it stands for, although It sounds like I'll be finding out shortly
;-)


Regards,
Vic Eldridge
 
If you are never displaying the item why use Close? Just use Save and
dispose of the object.

.Attachments.Add ("C:\SomeBugs4U2.exe")
.Save
End With
Set objMailItem = Nothing
 
Hi Vic,
You mentioned you don't have Outlook 2003. Does that mean you don't see
the same problem in previous versions ?

that means: I can´t believe that the save method doesn´t work but if you
are saying that it doesn´t I would have to test your code.
I'm fine with VBA but I'm new to the OOM. As for CDO, I don't even know
what it stands for, although It sounds like I'll be finding out
shortly

CDO is an optional installation for OL2k and later. You need a reference
on it via Extras/References/"Microsoft CDO 1.21 Library".
 
Hi Micheal,
that means: I can´t believe that the save method doesn´t work but if you
are saying that it doesn´t I would have to test your code.

What I'm seeing is that the Save method successfully saves the new
email in
my Drafts folder, however if I then manually open then close the newly
created
email (without making any changes to it), Outlook then shows the Save
Changes dialog, which seems to me to be wrong. If no changes were
made, why should I
be prompted to save changes ?


For example, the following code creates an email in my Drafts folder
that
behaves correctly when I manually open then close it.

Sub CreateEmail()
With Application.CreateItem(olMailItem)
.To = "(e-mail address removed)"
.Subject = "Subject Text"
.Body = "Body Text"
.Save
End With
End Sub



The email created by the following code does NOT behave correctly. If
I
manually open then close it, Outlook asks if I want to save changes,
even
though I made no changes to it.

Sub CreateEmailWithAttachment()
With Application.CreateItem(olMailItem)
.To = "(e-mail address removed)"
.Subject = "Subject Text"
.Body = "Body Text"
.Attachments.Add ("C:\Test.txt")
.Save
End With
End Sub


The only difference between the two pieces of code is that the second
one
attaches a file, the first one does not.


Regards,
Vic Eldridge
 
Thanks for taking a look at this Ken. Could you please read my latest
reply to Micheal Bauer. Hopefully it will further clarify the problem
I'm seeing.


Regards,
Vic Eldridge
 
Hi Vic,

good resolve the recipients collection before saving. Otherwise OL
is doing that while the item is opened and then there are changes, in
fact.
 
Thanks again Micheal and Ken.

Resolving the recipients made no difference to the outcome. I still
don't know what the solution is. I'm also seeing two WinXP/Office20003
machines behave differently (both erroneously) with regards to saving
mailitems with attachments. As long as there is no attachment, saving
works as one would expect. As soon as an attachment is made, saves
don't work correctly (be they issued manually, or via code).
It's now time to cut my losses and write it off as an Outlook "quirk".
I can reproduce the situation manually which at least will prove to my
users that it's Microsoft's bug, not mine.

Thanks again for your help.

Regards,
Vic Eldridge
 
Hi Vic,

here is a sample for you using CDO. What is about this?

Sub BugInSaveChangesDialogCDO()
Dim oSess As MAPI.Session
Dim oMsg As MAPI.Message
Dim oFld As MAPI.Messages

Set oSess = CreateObject("MAPI.Session")
oSess.LogOn , , False, False, , True
Set oFld = oSess.Outbox.Messages
Set oMsg = oFld.Add("subject", "text")
With oMsg.Recipients
.Add "(e-mail address removed)"
.Resolve
End With
oMsg.Attachments.Add "C:\Programme\MBBau\mbbau.exe"
oMsg.Update True
End Sub
 
Back
Top