check if mail was sent - still not working...

  • Thread starter Thread starter VilMarci
  • Start date Start date
V

VilMarci

Hi all,
I just can't understand why this code is not working...
I display a message with infos collected from a form and have the option for
the user to send or close the mail...
I want to check if the mail was sent and then set things in the db...

Why is that the value of otlMail.Sent is always FALSE? Doesn't matter if I
sent the mail or not... Tried to replace the .Display to .Send, then I get
an error message: the item has been moved or deleted...

Is there any other solution?
Any ideas?

Thanks,
Marton

otlMail.HTMLBody = strMailBody & "Dear " & Me![Last name] & Me![First name]
& ",<BR>" & strBody

'otlMail.SentOnBehalfOfName = "(e-mail address removed)"
otlMail.To = strCim
otlMail.Subject = "Your application"
otlMail.Attachments.Add "Z:\MailSrcDoc\CandidateEmail.doc"
otlMail.Display

If otlMail.Sent = True Then 'always false

strMessage = "Message SENT to: " & strNev
MsgBox (strMessage)

Else
strMessage = "Message NOT SENT to: " '& strNev
MsgBox (strMessage)
 
The MailItem object is not valid for further use after it has been Sent
because the object is closed and it is moved to the Sent Items folder (unless
otherwise specified).

It would be better to declare your MailItem object WithEvents and trap the
Send event, where you can be sure that the message has been sent (unless you
cancel the event).

Otherwise, you'll have to write additional code to locate the message in the
Sent Items folder to do futher work with it.
 
Hi,
Thanks for the reply.
So there's no easy way for this check.

Can you show me a short code how to do that "trap the send event"?

Thanks,
Marton

Eric Legault said:
The MailItem object is not valid for further use after it has been Sent
because the object is closed and it is moved to the Sent Items folder (unless
otherwise specified).

It would be better to declare your MailItem object WithEvents and trap the
Send event, where you can be sure that the message has been sent (unless you
cancel the event).

Otherwise, you'll have to write additional code to locate the message in the
Sent Items folder to do futher work with it.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

VilMarci said:
Hi all,
I just can't understand why this code is not working...
I display a message with infos collected from a form and have the option for
the user to send or close the mail...
I want to check if the mail was sent and then set things in the db...

Why is that the value of otlMail.Sent is always FALSE? Doesn't matter if I
sent the mail or not... Tried to replace the .Display to .Send, then I get
an error message: the item has been moved or deleted...

Is there any other solution?
Any ideas?

Thanks,
Marton

otlMail.HTMLBody = strMailBody & "Dear " & Me![Last name] & Me![First name]
& ",<BR>" & strBody

'otlMail.SentOnBehalfOfName = "(e-mail address removed)"
otlMail.To = strCim
otlMail.Subject = "Your application"
otlMail.Attachments.Add "Z:\MailSrcDoc\CandidateEmail.doc"
otlMail.Display

If otlMail.Sent = True Then 'always false

strMessage = "Message SENT to: " & strNev
MsgBox (strMessage)

Else
strMessage = "Message NOT SENT to: " '& strNev
MsgBox (strMessage)
 
See this article:

Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/articles/2224.aspx

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

VilMarci said:
Hi,
Thanks for the reply.
So there's no easy way for this check.

Can you show me a short code how to do that "trap the send event"?

Thanks,
Marton

Eric Legault said:
The MailItem object is not valid for further use after it has been Sent
because the object is closed and it is moved to the Sent Items folder (unless
otherwise specified).

It would be better to declare your MailItem object WithEvents and trap the
Send event, where you can be sure that the message has been sent (unless you
cancel the event).

Otherwise, you'll have to write additional code to locate the message in the
Sent Items folder to do futher work with it.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

VilMarci said:
Hi all,
I just can't understand why this code is not working...
I display a message with infos collected from a form and have the option for
the user to send or close the mail...
I want to check if the mail was sent and then set things in the db...

Why is that the value of otlMail.Sent is always FALSE? Doesn't matter if I
sent the mail or not... Tried to replace the .Display to .Send, then I get
an error message: the item has been moved or deleted...

Is there any other solution?
Any ideas?

Thanks,
Marton

otlMail.HTMLBody = strMailBody & "Dear " & Me![Last name] & Me![First name]
& ",<BR>" & strBody

'otlMail.SentOnBehalfOfName = "(e-mail address removed)"
otlMail.To = strCim
otlMail.Subject = "Your application"
otlMail.Attachments.Add "Z:\MailSrcDoc\CandidateEmail.doc"
otlMail.Display

If otlMail.Sent = True Then 'always false

strMessage = "Message SENT to: " & strNev
MsgBox (strMessage)

Else
strMessage = "Message NOT SENT to: " '& strNev
MsgBox (strMessage)
 
I've been there. Unfortunately it's not really what I need. Or at least not
in this form. The problem is that I'm doing this in Access, I don't have
access to the user's machines to deploy codes to their outlook.

Ok, I didn't write here. So I have a code that runs in access and generates
mail base on the db.
All I need is a simple loop like:

while x = 0
if cancelled then x=1
if sent then x = 2
wend
'Here then I can do things with x...

Tried with error handling (reading .Sent property of a Sent item returns
error) but I still have 2 events with no difference:
1. the mail is still on the screen
2. the mail is cancelled

Any hope to do this? Sorry, I'm still a beginner :(
Is this possible?
Marton

Eric Legault said:
See this article:

Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/articles/2224.aspx

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

VilMarci said:
Hi,
Thanks for the reply.
So there's no easy way for this check.

Can you show me a short code how to do that "trap the send event"?

Thanks,
Marton

Eric Legault said:
The MailItem object is not valid for further use after it has been Sent
because the object is closed and it is moved to the Sent Items folder (unless
otherwise specified).

It would be better to declare your MailItem object WithEvents and trap the
Send event, where you can be sure that the message has been sent
(unless
you
cancel the event).

Otherwise, you'll have to write additional code to locate the message
in
the
Sent Items folder to do futher work with it.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

:

Hi all,
I just can't understand why this code is not working...
I display a message with infos collected from a form and have the
option
for
the user to send or close the mail...
I want to check if the mail was sent and then set things in the db...

Why is that the value of otlMail.Sent is always FALSE? Doesn't
matter
if I
sent the mail or not... Tried to replace the .Display to .Send, then
I
get
an error message: the item has been moved or deleted...

Is there any other solution?
Any ideas?

Thanks,
Marton

otlMail.HTMLBody = strMailBody & "Dear " & Me![Last name] &
Me![First
name]
& ",<BR>" & strBody

'otlMail.SentOnBehalfOfName = "(e-mail address removed)"
otlMail.To = strCim
otlMail.Subject = "Your application"
otlMail.Attachments.Add "Z:\MailSrcDoc\CandidateEmail.doc"
otlMail.Display

If otlMail.Sent = True Then 'always false

strMessage = "Message SENT to: " & strNev
MsgBox (strMessage)

Else
strMessage = "Message NOT SENT to: " '& strNev
MsgBox (strMessage)
 
Sorry, I didn't realize that was you posting in my blog as well. I just
added a code snippet there to help you with the Send method.

Basically, call MailItem.Display(True) to force code after the method call
to wait until the user is done with the e-mail. Now, you can do two things:
after the call, if you can access any MailItem properties then the message
has not been sent; if you can't due to an error, the reference to the message
is broken because it has been sent and is no longer accessible. Alternately,
you can pass a value to a module level variable in the Send event that you
can access after the Display call to verify that the message has indeed been
sent without relying on an error handler.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

VilMarci said:
I've been there. Unfortunately it's not really what I need. Or at least not
in this form. The problem is that I'm doing this in Access, I don't have
access to the user's machines to deploy codes to their outlook.

Ok, I didn't write here. So I have a code that runs in access and generates
mail base on the db.
All I need is a simple loop like:

while x = 0
if cancelled then x=1
if sent then x = 2
wend
'Here then I can do things with x...

Tried with error handling (reading .Sent property of a Sent item returns
error) but I still have 2 events with no difference:
1. the mail is still on the screen
2. the mail is cancelled

Any hope to do this? Sorry, I'm still a beginner :(
Is this possible?
Marton

Eric Legault said:
See this article:

Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/articles/2224.aspx

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

VilMarci said:
Hi,
Thanks for the reply.
So there's no easy way for this check.

Can you show me a short code how to do that "trap the send event"?

Thanks,
Marton

message The MailItem object is not valid for further use after it has been Sent
because the object is closed and it is moved to the Sent Items folder
(unless
otherwise specified).

It would be better to declare your MailItem object WithEvents and trap the
Send event, where you can be sure that the message has been sent (unless
you
cancel the event).

Otherwise, you'll have to write additional code to locate the message in
the
Sent Items folder to do futher work with it.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

:

Hi all,
I just can't understand why this code is not working...
I display a message with infos collected from a form and have the option
for
the user to send or close the mail...
I want to check if the mail was sent and then set things in the db...

Why is that the value of otlMail.Sent is always FALSE? Doesn't matter
if I
sent the mail or not... Tried to replace the .Display to .Send, then I
get
an error message: the item has been moved or deleted...

Is there any other solution?
Any ideas?

Thanks,
Marton

otlMail.HTMLBody = strMailBody & "Dear " & Me![Last name] & Me![First
name]
& ",<BR>" & strBody

'otlMail.SentOnBehalfOfName = "(e-mail address removed)"
otlMail.To = strCim
otlMail.Subject = "Your application"
otlMail.Attachments.Add "Z:\MailSrcDoc\CandidateEmail.doc"
otlMail.Display

If otlMail.Sent = True Then 'always false

strMessage = "Message SENT to: " & strNev
MsgBox (strMessage)

Else
strMessage = "Message NOT SENT to: " '& strNev
MsgBox (strMessage)
 
Sorry I didn't realize that I'm writing to your blog :))
This .Display(True) was what I needed.

Now the code looks like.
[....]
otlMail.Display (True)

HibaCheck = otlMail.Sent

Exit Sub
Handler:

DoCmd.SetWarnings False
DoCmd.OpenQuery "qAppendNetworkMail" 'a query that updates the SentMails
table
DoCmd.SetWarnings True

End Sub

Thanks for all the help!

Marton


Eric Legault said:
Sorry, I didn't realize that was you posting in my blog as well. I just
added a code snippet there to help you with the Send method.

Basically, call MailItem.Display(True) to force code after the method call
to wait until the user is done with the e-mail. Now, you can do two things:
after the call, if you can access any MailItem properties then the message
has not been sent; if you can't due to an error, the reference to the message
is broken because it has been sent and is no longer accessible. Alternately,
you can pass a value to a module level variable in the Send event that you
can access after the Display call to verify that the message has indeed been
sent without relying on an error handler.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

VilMarci said:
I've been there. Unfortunately it's not really what I need. Or at least not
in this form. The problem is that I'm doing this in Access, I don't have
access to the user's machines to deploy codes to their outlook.

Ok, I didn't write here. So I have a code that runs in access and generates
mail base on the db.
All I need is a simple loop like:

while x = 0
if cancelled then x=1
if sent then x = 2
wend
'Here then I can do things with x...

Tried with error handling (reading .Sent property of a Sent item returns
error) but I still have 2 events with no difference:
1. the mail is still on the screen
2. the mail is cancelled

Any hope to do this? Sorry, I'm still a beginner :(
Is this possible?
Marton

Eric Legault said:
See this article:

Getting a Handle on Your E-mails with VBA:
http://blogs.officezealot.com/legault/articles/2224.aspx

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

:

Hi,
Thanks for the reply.
So there's no easy way for this check.

Can you show me a short code how to do that "trap the send event"?

Thanks,
Marton

message The MailItem object is not valid for further use after it has been Sent
because the object is closed and it is moved to the Sent Items folder
(unless
otherwise specified).

It would be better to declare your MailItem object WithEvents and
trap
the
Send event, where you can be sure that the message has been sent (unless
you
cancel the event).

Otherwise, you'll have to write additional code to locate the
message
in
the
Sent Items folder to do futher work with it.

--
Eric Legault - B.A, MCP, MCSD, Outlook MVP
--------------------------------------------------
{Private e-mails ignored}
Job: http://www.imaginets.com
Blog: http://blogs.officezealot.com/legault/

:

Hi all,
I just can't understand why this code is not working...
I display a message with infos collected from a form and have
the
option
for
the user to send or close the mail...
I want to check if the mail was sent and then set things in the db...

Why is that the value of otlMail.Sent is always FALSE? Doesn't matter
if I
sent the mail or not... Tried to replace the .Display to .Send,
then
I
get
an error message: the item has been moved or deleted...

Is there any other solution?
Any ideas?

Thanks,
Marton

otlMail.HTMLBody = strMailBody & "Dear " & Me![Last name] & Me![First
name]
& ",<BR>" & strBody

'otlMail.SentOnBehalfOfName = "(e-mail address removed)"
otlMail.To = strCim
otlMail.Subject = "Your application"
otlMail.Attachments.Add "Z:\MailSrcDoc\CandidateEmail.doc"
otlMail.Display

If otlMail.Sent = True Then 'always false

strMessage = "Message SENT to: " & strNev
MsgBox (strMessage)

Else
strMessage = "Message NOT SENT to: " '& strNev
MsgBox (strMessage)
 
Back
Top