By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,132 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,132 IT Pros & Developers. It's quick & easy.

creating an e-mail from acc2007 in Outlook using MS Outlook Library 12

P: n/a
ARC
In case anyone has ran into this yet. The following code used to work with
older versions of the MS Outlook library, but would error out in 2007:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)

After doing some testing, I found that the code will work provided that you
first OPEN MS Outlook. In previous versions, you didn't have to have outlook
open, and it would still add the e-mail to the outbox.

If there's a fix to where you wouldn't need to open Outlook, I'd love to
know.

FYI, the error code if you don't first open Outlook is Err = 287. It would
error out upon hitting the .recipients.add statement. With Outlook opened
first, all runs well.

Aug 21 '07 #1
Share this Question
Share on Google+
9 Replies


P: n/a
On Mon, 20 Aug 2007 21:30:19 -0500, "ARC" <an**@andyc.comwrote:

But your CreateObject line opens Outlook, so I don't understand.
Just add:
objOutlook.Visible = True
and you can see for yourself.

Sorry I don't have Outlook2007 installed properly here so I cannot
test this further.
What is the Err.Description when you take an error?

-Tom.

>In case anyone has ran into this yet. The following code used to work with
older versions of the MS Outlook library, but would error out in 2007:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)

After doing some testing, I found that the code will work provided that you
first OPEN MS Outlook. In previous versions, you didn't have to have outlook
open, and it would still add the e-mail to the outbox.

If there's a fix to where you wouldn't need to open Outlook, I'd love to
know.

FYI, the error code if you don't first open Outlook is Err = 287. It would
error out upon hitting the .recipients.add statement. With Outlook opened
first, all runs well.

Aug 21 '07 #2

P: n/a
ARC
Tom,

As an update to this. Putting the line: ObjOutlook.Visible = true had no
affect.

I believe the change is in the new reference library: MS Outlook 12

As I tested in my Access 97 runtime app, and it still errored out with the
same message. However, if you first open Outlook, then there is no error,
and it works as it should.

Again, in previous versions of the library file, you didn't need to first
open Outlook, and messages would be written to Outlook's outbox. Not so with
v12, but at least it works, and chances are the user will have Outlook open
most of the time.

Andy
"Tom van Stiphout" <no*************@cox.netwrote in message
news:p4********************************@4ax.com...
On Mon, 20 Aug 2007 21:30:19 -0500, "ARC" <an**@andyc.comwrote:

But your CreateObject line opens Outlook, so I don't understand.
Just add:
objOutlook.Visible = True
and you can see for yourself.

Sorry I don't have Outlook2007 installed properly here so I cannot
test this further.
What is the Err.Description when you take an error?

-Tom.

>>In case anyone has ran into this yet. The following code used to work with
older versions of the MS Outlook library, but would error out in 2007:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)

After doing some testing, I found that the code will work provided that
you
first OPEN MS Outlook. In previous versions, you didn't have to have
outlook
open, and it would still add the e-mail to the outbox.

If there's a fix to where you wouldn't need to open Outlook, I'd love to
know.

FYI, the error code if you don't first open Outlook is Err = 287. It would
error out upon hitting the .recipients.add statement. With Outlook opened
first, all runs well.


Aug 22 '07 #3

P: n/a
ARC
Oh yes, and I did add error-trapping code for the error number given. If it
hits that, I inform the user that Outlook must be open prior to creating the
e-mail from the Access program.

"Tom van Stiphout" <no*************@cox.netwrote in message
news:p4********************************@4ax.com...
On Mon, 20 Aug 2007 21:30:19 -0500, "ARC" <an**@andyc.comwrote:

But your CreateObject line opens Outlook, so I don't understand.
Just add:
objOutlook.Visible = True
and you can see for yourself.

Sorry I don't have Outlook2007 installed properly here so I cannot
test this further.
What is the Err.Description when you take an error?

-Tom.

>>In case anyone has ran into this yet. The following code used to work with
older versions of the MS Outlook library, but would error out in 2007:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)

After doing some testing, I found that the code will work provided that
you
first OPEN MS Outlook. In previous versions, you didn't have to have
outlook
open, and it would still add the e-mail to the outbox.

If there's a fix to where you wouldn't need to open Outlook, I'd love to
know.

FYI, the error code if you don't first open Outlook is Err = 287. It would
error out upon hitting the .recipients.add statement. With Outlook opened
first, all runs well.


Aug 22 '07 #4

P: n/a
On Aug 20, 10:30 pm, "ARC" <a...@andyc.comwrote:
In case anyone has ran into this yet. The following code used to work with
older versions of the MS Outlook library, but would error out in 2007:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)

After doing some testing, I found that the code will work provided that you
first OPEN MS Outlook. In previous versions, you didn't have to have outlook
open, and it would still add the e-mail to the outbox.

If there's a fix to where you wouldn't need to open Outlook, I'd love to
know.

FYI, the error code if you don't first open Outlook is Err = 287. It would
error out upon hitting the .recipients.add statement. With Outlook opened
first, all runs well.
I know this is a long shot, but your problem may have been caused by
timing issues. Perhaps the new version of Outlook is taking longer to
open. The code, trying to be helpful and efficient, continues on
without waiting for CreateObject to finish and discovers that Outlook
is not open yet. That would explain why it works when Outlook is
already open. BTW, CreateObject seems never to create more than one
instance of Outlook. Try some DoEvent's in a loop (maybe 2000 times)
after your CreateObject call to see if that's the case. It's true
that the 'Set objOutlookMsg = objOutlook.CreateItem(olMailItem)' line
seems like it might require Outlook to be open, but perhaps it
doesn't. You can also combine this with Tom's suggestion by putting
objOutlook.Visible = True right before the DoEvents loop.

James A. Fortune
CD********@FortuneJames.com

Aug 22 '07 #5

P: n/a
ARC
I'll try that, and report back. I already have some looping code that pauses
a few seconds, I'll insert that and let you know. Outlook 2007 does take
longer to load. When you first launch, there are a few sections that say
"..loading.." , so it could very well be the timing of it all.

I don't know if I can use the ojbOutlook.visible property, as on one screen,
it's a batch e-mail process of invoices to many different customers, etc.

I'll post the results soon..and thanks for the idea!

<CD********@FortuneJames.comwrote in message
news:11**********************@z24g2000prh.googlegr oups.com...
On Aug 20, 10:30 pm, "ARC" <a...@andyc.comwrote:
>In case anyone has ran into this yet. The following code used to work
with
older versions of the MS Outlook library, but would error out in 2007:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)

After doing some testing, I found that the code will work provided that
you
first OPEN MS Outlook. In previous versions, you didn't have to have
outlook
open, and it would still add the e-mail to the outbox.

If there's a fix to where you wouldn't need to open Outlook, I'd love to
know.

FYI, the error code if you don't first open Outlook is Err = 287. It
would
error out upon hitting the .recipients.add statement. With Outlook opened
first, all runs well.

I know this is a long shot, but your problem may have been caused by
timing issues. Perhaps the new version of Outlook is taking longer to
open. The code, trying to be helpful and efficient, continues on
without waiting for CreateObject to finish and discovers that Outlook
is not open yet. That would explain why it works when Outlook is
already open. BTW, CreateObject seems never to create more than one
instance of Outlook. Try some DoEvent's in a loop (maybe 2000 times)
after your CreateObject call to see if that's the case. It's true
that the 'Set objOutlookMsg = objOutlook.CreateItem(olMailItem)' line
seems like it might require Outlook to be open, but perhaps it
doesn't. You can also combine this with Tom's suggestion by putting
objOutlook.Visible = True right before the DoEvents loop.

James A. Fortune
CD********@FortuneJames.com

Aug 22 '07 #6

P: n/a
ARC
No luck. I even tried setting the pause loop very high.

I looked into the new settings in Outlook, especially those in the trust
center, and tried a few options dealing with unsigned macros, and
programmatic access, all to no avail.

For now, I'll just trap the error code, and inform the user that they need
to first have Outlook opened. I never noticed a problem in previous versions
of the MS Outlook Libary. Something new in 2007, I suppose.

Thanks again,

Andy
"ARC" <an**@andyc.comwrote in message
news:%p******************@newssvr11.news.prodigy.n et...
I'll try that, and report back. I already have some looping code that
pauses a few seconds, I'll insert that and let you know. Outlook 2007 does
take longer to load. When you first launch, there are a few sections that
say "..loading.." , so it could very well be the timing of it all.

I don't know if I can use the ojbOutlook.visible property, as on one
screen, it's a batch e-mail process of invoices to many different
customers, etc.

I'll post the results soon..and thanks for the idea!

<CD********@FortuneJames.comwrote in message
news:11**********************@z24g2000prh.googlegr oups.com...
>On Aug 20, 10:30 pm, "ARC" <a...@andyc.comwrote:
>>In case anyone has ran into this yet. The following code used to work
with
older versions of the MS Outlook library, but would error out in 2007:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)

After doing some testing, I found that the code will work provided that
you
first OPEN MS Outlook. In previous versions, you didn't have to have
outlook
open, and it would still add the e-mail to the outbox.

If there's a fix to where you wouldn't need to open Outlook, I'd love to
know.

FYI, the error code if you don't first open Outlook is Err = 287. It
would
error out upon hitting the .recipients.add statement. With Outlook
opened
first, all runs well.

I know this is a long shot, but your problem may have been caused by
timing issues. Perhaps the new version of Outlook is taking longer to
open. The code, trying to be helpful and efficient, continues on
without waiting for CreateObject to finish and discovers that Outlook
is not open yet. That would explain why it works when Outlook is
already open. BTW, CreateObject seems never to create more than one
instance of Outlook. Try some DoEvent's in a loop (maybe 2000 times)
after your CreateObject call to see if that's the case. It's true
that the 'Set objOutlookMsg = objOutlook.CreateItem(olMailItem)' line
seems like it might require Outlook to be open, but perhaps it
doesn't. You can also combine this with Tom's suggestion by putting
objOutlook.Visible = True right before the DoEvents loop.

James A. Fortune
CD********@FortuneJames.com


Aug 22 '07 #7

P: n/a
ARC
By the way, if you put a break and step through the code, the line below
triggers the On Error (where SendAddr is a string loaded with a valid
e-mail):

Set objOutlookRecip = .Recipients.Add(SendAddr)
"ARC" <an**@andyc.comwrote in message
news:%p******************@newssvr11.news.prodigy.n et...
I'll try that, and report back. I already have some looping code that
pauses a few seconds, I'll insert that and let you know. Outlook 2007 does
take longer to load. When you first launch, there are a few sections that
say "..loading.." , so it could very well be the timing of it all.

I don't know if I can use the ojbOutlook.visible property, as on one
screen, it's a batch e-mail process of invoices to many different
customers, etc.

I'll post the results soon..and thanks for the idea!

<CD********@FortuneJames.comwrote in message
news:11**********************@z24g2000prh.googlegr oups.com...
>On Aug 20, 10:30 pm, "ARC" <a...@andyc.comwrote:
>>In case anyone has ran into this yet. The following code used to work
with
older versions of the MS Outlook library, but would error out in 2007:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)

After doing some testing, I found that the code will work provided that
you
first OPEN MS Outlook. In previous versions, you didn't have to have
outlook
open, and it would still add the e-mail to the outbox.

If there's a fix to where you wouldn't need to open Outlook, I'd love to
know.

FYI, the error code if you don't first open Outlook is Err = 287. It
would
error out upon hitting the .recipients.add statement. With Outlook
opened
first, all runs well.

I know this is a long shot, but your problem may have been caused by
timing issues. Perhaps the new version of Outlook is taking longer to
open. The code, trying to be helpful and efficient, continues on
without waiting for CreateObject to finish and discovers that Outlook
is not open yet. That would explain why it works when Outlook is
already open. BTW, CreateObject seems never to create more than one
instance of Outlook. Try some DoEvent's in a loop (maybe 2000 times)
after your CreateObject call to see if that's the case. It's true
that the 'Set objOutlookMsg = objOutlook.CreateItem(olMailItem)' line
seems like it might require Outlook to be open, but perhaps it
doesn't. You can also combine this with Tom's suggestion by putting
objOutlook.Visible = True right before the DoEvents loop.

James A. Fortune
CD********@FortuneJames.com


Aug 22 '07 #8

P: n/a
ARC wrote:
For now, I'll just trap the error code, and inform the user that they need
to first have Outlook opened. I never noticed a problem in previous versions
of the MS Outlook Libary. Something new in 2007, I suppose.
If you care, that's what I do. I check to see if Outlook is open, I
inform if it's not open and cancel. I don't know which profile is being
used and I don't care. I figure if someone wants to send an email, open
the email program first and select the profile.
>
Thanks again,

Andy
"ARC" <an**@andyc.comwrote in message
news:%p******************@newssvr11.news.prodigy.n et...
>>I'll try that, and report back. I already have some looping code that
pauses a few seconds, I'll insert that and let you know. Outlook 2007 does
take longer to load. When you first launch, there are a few sections that
say "..loading.." , so it could very well be the timing of it all.

I don't know if I can use the ojbOutlook.visible property, as on one
screen, it's a batch e-mail process of invoices to many different
customers, etc.

I'll post the results soon..and thanks for the idea!

<CD********@FortuneJames.comwrote in message
news:11**********************@z24g2000prh.google groups.com...
>>>On Aug 20, 10:30 pm, "ARC" <a...@andyc.comwrote:

In case anyone has ran into this yet. The following code used to work
with
older versions of the MS Outlook library, but would error out in 2007:

Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)

After doing some testing, I found that the code will work provided that
you
first OPEN MS Outlook. In previous versions, you didn't have to have
outlook
open, and it would still add the e-mail to the outbox.

If there's a fix to where you wouldn't need to open Outlook, I'd love to
know.

FYI, the error code if you don't first open Outlook is Err = 287. It
would
error out upon hitting the .recipients.add statement. With Outlook
opened
first, all runs well.

I know this is a long shot, but your problem may have been caused by
timing issues. Perhaps the new version of Outlook is taking longer to
open. The code, trying to be helpful and efficient, continues on
without waiting for CreateObject to finish and discovers that Outlook
is not open yet. That would explain why it works when Outlook is
already open. BTW, CreateObject seems never to create more than one
instance of Outlook. Try some DoEvent's in a loop (maybe 2000 times)
after your CreateObject call to see if that's the case. It's true
that the 'Set objOutlookMsg = objOutlook.CreateItem(olMailItem)' line
seems like it might require Outlook to be open, but perhaps it
doesn't. You can also combine this with Tom's suggestion by putting
objOutlook.Visible = True right before the DoEvents loop.

James A. Fortune
CD********@FortuneJames.com


Aug 23 '07 #9

P: n/a
ARC
'course I do! And thanks for the reply.

"Salad" <oi*@vinegar.comwrote in message
news:13*************@corp.supernews.com...
ARC wrote:
>For now, I'll just trap the error code, and inform the user that they
need to first have Outlook opened. I never noticed a problem in previous
versions of the MS Outlook Libary. Something new in 2007, I suppose.

If you care, that's what I do. I check to see if Outlook is open, I
inform if it's not open and cancel. I don't know which profile is being
used and I don't care. I figure if someone wants to send an email, open
the email program first and select the profile.
>>
Thanks again,

Andy
"ARC" <an**@andyc.comwrote in message
news:%p******************@newssvr11.news.prodigy. net...
>>>I'll try that, and report back. I already have some looping code that
pauses a few seconds, I'll insert that and let you know. Outlook 2007
does take longer to load. When you first launch, there are a few sections
that say "..loading.." , so it could very well be the timing of it all.

I don't know if I can use the ojbOutlook.visible property, as on one
screen, it's a batch e-mail process of invoices to many different
customers, etc.

I'll post the results soon..and thanks for the idea!

<CD********@FortuneJames.comwrote in message
news:11**********************@z24g2000prh.googl egroups.com...

On Aug 20, 10:30 pm, "ARC" <a...@andyc.comwrote:

>In case anyone has ran into this yet. The following code used to work
>with
>older versions of the MS Outlook library, but would error out in 2007:
>
>Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment
Set objOutlook = CreateObject("Outlook.Application")
' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
With objOutlookMsg
Set objOutlookRecip = .Recipients.Add(SendAddr)
>
>After doing some testing, I found that the code will work provided that
>you
>first OPEN MS Outlook. In previous versions, you didn't have to have
>outlook
>open, and it would still add the e-mail to the outbox.
>
>If there's a fix to where you wouldn't need to open Outlook, I'd love
>to
>know.
>
>FYI, the error code if you don't first open Outlook is Err = 287. It
>would
>error out upon hitting the .recipients.add statement. With Outlook
>opened
>first, all runs well.

I know this is a long shot, but your problem may have been caused by
timing issues. Perhaps the new version of Outlook is taking longer to
open. The code, trying to be helpful and efficient, continues on
without waiting for CreateObject to finish and discovers that Outlook
is not open yet. That would explain why it works when Outlook is
already open. BTW, CreateObject seems never to create more than one
instance of Outlook. Try some DoEvent's in a loop (maybe 2000 times)
after your CreateObject call to see if that's the case. It's true
that the 'Set objOutlookMsg = objOutlook.CreateItem(olMailItem)' line
seems like it might require Outlook to be open, but perhaps it
doesn't. You can also combine this with Tom's suggestion by putting
objOutlook.Visible = True right before the DoEvents loop.

James A. Fortune
CD********@FortuneJames.com
Aug 23 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.