Access 2000 / Outlook 2007

B

bh

I'm trying to email from Access 2000 using the following:

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")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("Email addresses separated
by semicolons")
objOutlookRecip.Type = olTo
.Subject = "Whatever subject"
.Body = "Whatever message text"
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Display
End With

Set objOutlook = Nothing
SendMessage = True

This process always worked fine with Outlook 2000 and then Outlook 2003;
however, in Outlook 2007, I get an Error 287 (Object definition error). I
was using Outlook Library 11.0, previously, but now some users are using
Outlook 2007 instead of '03. When I put the program on a machine with 2007,
however, the Library 12.0 is showing as referenced in my code-behind
(appearing to have grabbed automatically)... The machine I actually
developed the app on has Outlook 2003, and only some of the users will have
2007, and I manually had chosen the 11.0 library. Any ideas on how to
resolve this would be helpful.
 
S

Sue Mosher [MVP-Outlook]

[non-developer newsgroup removed]

You didn't say which statement raises the error. If you get an error from code statements like these:

Dim ol as New Outlook.Application

Set ol = CreateObject("Outlook.Application")

the cause may be an anti-virus program on your computer that has a feature to block Outlook scripting. If so, the solution is to turn off the script blocking feature. You may need to contact technical support for your anti-virus program to find out how to do that.

I've also seen reports that setting the server parameter can resolve this problem in some situations:

Set ol = CreateObject("Outlook.Applicaton", localhost)
 
G

Guest

I tried similar code:
Set objOutlook = CreateObject("Outlook.Application")
Set objOlns = objOutlook.GetNamespace("MAPI")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
If Len(lsEmailAddress) > 0 Then
objOutlookMsg.Recipients.Add lsEmailAddress
End If

It failed if I did not have Outlook open but works fine with Outlook open.
Sue Mosher said:
[non-developer newsgroup removed]

You didn't say which statement raises the error. If you get an error from code statements like these:

Dim ol as New Outlook.Application

Set ol = CreateObject("Outlook.Application")

the cause may be an anti-virus program on your computer that has a feature to block Outlook scripting. If so, the solution is to turn off the script blocking feature. You may need to contact technical support for your anti-virus program to find out how to do that.

I've also seen reports that setting the server parameter can resolve this problem in some situations:

Set ol = CreateObject("Outlook.Applicaton", localhost)


--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


bh said:
I'm trying to email from Access 2000 using the following:

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")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("Email addresses separated
by semicolons")
objOutlookRecip.Type = olTo
.Subject = "Whatever subject"
.Body = "Whatever message text"
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Display
End With

Set objOutlook = Nothing
SendMessage = True

This process always worked fine with Outlook 2000 and then Outlook 2003;
however, in Outlook 2007, I get an Error 287 (Object definition error). I
was using Outlook Library 11.0, previously, but now some users are using
Outlook 2007 instead of '03. When I put the program on a machine with 2007,
however, the Library 12.0 is showing as referenced in my code-behind
(appearing to have grabbed automatically)... The machine I actually
developed the app on has Outlook 2003, and only some of the users will have
2007, and I manually had chosen the 11.0 library. Any ideas on how to
resolve this would be helpful.
 
S

Sue Mosher [MVP-Outlook]

You didn't say which statement fails.

If Outlook is not already running, then you may need to use a Namespace.Logon statement to start Outlook with a specific profile or allow the user to choose the mail profile.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Tim Freeman said:
I tried similar code:
Set objOutlook = CreateObject("Outlook.Application")
Set objOlns = objOutlook.GetNamespace("MAPI")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
If Len(lsEmailAddress) > 0 Then
objOutlookMsg.Recipients.Add lsEmailAddress
End If

It failed if I did not have Outlook open but works fine with Outlook open.
Sue Mosher said:
[non-developer newsgroup removed]

You didn't say which statement raises the error. If you get an error from code statements like these:

Dim ol as New Outlook.Application

Set ol = CreateObject("Outlook.Application")

the cause may be an anti-virus program on your computer that has a feature to block Outlook scripting. If so, the solution is to turn off the script blocking feature. You may need to contact technical support for your anti-virus program to find out how to do that.

I've also seen reports that setting the server parameter can resolve this problem in some situations:

Set ol = CreateObject("Outlook.Applicaton", localhost)


bh said:
I'm trying to email from Access 2000 using the following:

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")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("Email addresses separated
by semicolons")
objOutlookRecip.Type = olTo
.Subject = "Whatever subject"
.Body = "Whatever message text"
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Display
End With

Set objOutlook = Nothing
SendMessage = True

This process always worked fine with Outlook 2000 and then Outlook 2003;
however, in Outlook 2007, I get an Error 287 (Object definition error). I
was using Outlook Library 11.0, previously, but now some users are using
Outlook 2007 instead of '03. When I put the program on a machine with 2007,
however, the Library 12.0 is showing as referenced in my code-behind
(appearing to have grabbed automatically)... The machine I actually
developed the app on has Outlook 2003, and only some of the users will have
2007, and I manually had chosen the 11.0 library. Any ideas on how to
resolve this would be helpful.
 
G

Guest

Thanks Sue, I was replying to BH as to why the code failed but mine failed
on the objOutlookMsg.Recipients.Add lsEmailAddress statement. It quite
happily creates the email and displays it afterwards but unless the user is
logged in, the recipient cannot be created.

Regards

Sue Mosher said:
You didn't say which statement fails.

If Outlook is not already running, then you may need to use a Namespace.Logon statement to start Outlook with a specific profile or allow the user to choose the mail profile.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Tim Freeman said:
I tried similar code:
Set objOutlook = CreateObject("Outlook.Application")
Set objOlns = objOutlook.GetNamespace("MAPI")

Set objOutlookMsg = objOutlook.CreateItem(olMailItem)
If Len(lsEmailAddress) > 0 Then
objOutlookMsg.Recipients.Add lsEmailAddress
End If

It failed if I did not have Outlook open but works fine with Outlook open.
Sue Mosher said:
[non-developer newsgroup removed]

You didn't say which statement raises the error. If you get an error from code statements like these:

Dim ol as New Outlook.Application

Set ol = CreateObject("Outlook.Application")

the cause may be an anti-virus program on your computer that has a feature to block Outlook scripting. If so, the solution is to turn off the script blocking feature. You may need to contact technical support for your anti-virus program to find out how to do that.

I've also seen reports that setting the server parameter can resolve this problem in some situations:

Set ol = CreateObject("Outlook.Applicaton", localhost)


I'm trying to email from Access 2000 using the following:

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")
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
Set objOutlookRecip = .Recipients.Add("Email addresses separated
by semicolons")
objOutlookRecip.Type = olTo
.Subject = "Whatever subject"
.Body = "Whatever message text"
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
Next
.Display
End With

Set objOutlook = Nothing
SendMessage = True

This process always worked fine with Outlook 2000 and then Outlook 2003;
however, in Outlook 2007, I get an Error 287 (Object definition error). I
was using Outlook Library 11.0, previously, but now some users are using
Outlook 2007 instead of '03. When I put the program on a machine with 2007,
however, the Library 12.0 is showing as referenced in my code-behind
(appearing to have grabbed automatically)... The machine I actually
developed the app on has Outlook 2003, and only some of the users will have
2007, and I manually had chosen the 11.0 library. Any ideas on how to
resolve this would be helpful.
 
S

Sue Mosher [MVP-Outlook]

Outlook should be able to resolve IsEmailAddress to a recipient if it is a straight SMTP address, but if you're passing a name that has to be resolved, a login is necessary. Otherwise, Outlook may not know what address lists are available for name resolution. You can add an objOlns.Login statement to either use a specific profile or prompt the user to choose one.
 
G

Guest

Sue Mosher said:
Outlook should be able to resolve IsEmailAddress to a recipient if it is a straight SMTP address, but if you're passing a name that has to be resolved, a login is necessary. Otherwise, Outlook may not know what address lists are available for name resolution. You can add an objOlns.Login statement to either use a specific profile or prompt the user to choose one.

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 

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