Email sent using OIutlook 2007 from Acsess 2003

  • Thread starter Cyberwolf0000 via AccessMonster.com
  • Start date
C

Cyberwolf0000 via AccessMonster.com

Hi all,

The company I am working for right now is getting ready to switch from Lotus
Notes to Outlook 2007. As such, I have an email routine that sends a pdf
file to several recipients. I have been doing a lot of research on the code
to send a pdf attachment. I am having several problems.

1. In the code provided below I have several lines commented out. Then are
all of the set lines to set the to, cc, bcc, subject, body and attachments.
The reason I commented out these lines and just ised the .to, .cc, .bcc is
because the code breaks on the set lines. It gives the error message
"Runtime error 287, Application defined or object defined error" I did set
up my references to the Outlook and office 12.0 object libraries. So when I
just did the .to and so forth, it works fine until I get to the .attachments
= strAttachPathFile where it breaks and gives me the error "Runtime error 5,
invalid procedure call or argument." If I could get to work with the sets
that would be ideal, but I will take any fix that can be provided.

TIA,

--
James B Gaylord
For the Wolf comes the strength of the Pack,
For the Pack comes the strength of the Wolf,
-R. Kipling
Office 2003 on Win XP SP2
 
C

Chris Freeman

There is no code posted below. I'm workign on the same process right now, and
have no error, so I would like to see your code.
 
J

jim1016

Initially, it alooks like you are in the right direction. But the viewer
needs to see your code to help.
Also, is this a command button or form you are trying to get to work?
Finally, have you googled MS Access Email. A list of subroutines are
provided for either single email entry or batch emails from a table with an
email column. In the latter you will rely on the messaging system to tell
you wich email is accurate and which wasn't. Then you need to update you
table with the email addresses so as not to repeat this process over and over
again.

Jim
jim1016.
 
C

Chris Freeman

A second review seems that you may be missing the .add on your attachments
line:

With myItem
.Subject = strSubject
.To = strRecipients
.Body = strBody
.Attachments.Add (strFullPath)
.Send
End With

Take a look here and see if you have the same problem.
 
J

jim1016

Initially, it alooks like you are in the right direction. But the viewer
needs to see your code to help.
Also, is this a command button or form you are trying to get to work?
Finally, have you googled MS Access Email. A list of subroutines are
provided for either single email entry or batch emails from a table with an
email column. In the latter you will rely on the messaging system to tell
you wich email is accurate and which wasn't. Then you need to update you
table with the email addresses so as not to repeat this process over and over
again.

Jim
jim1016.
 
T

Tony Toews [MVP]

Cyberwolf0000 via AccessMonster.com said:
I did set
up my references to the Outlook and office 12.0 object libraries.

You shouldn't need the Office 12 object library so I'd remove that.

Do the users already have Outlook 2007 deployed? Or some of them?
Consider switching your code to late binding once you have the code
running smoothly. This would then allow you to remove the reference
the Outlook so your app will execute correctly even if some users
don't yet have Outlook installed.

Also, in the future, your code will still work should some systems be
converted to the next version of Outlook and some are still at the
current version.

Late binding means you can safely remove the reference and only have
an error when the app executes lines of code in question. Rather than
erroring out while starting up the app and not allowing the users in
the app at all. Or when hitting a mid, left or trim function call.

This also is very useful when you don't know version of the external
application will reside on the target system. Or if your organization
is in the middle of moving from one version to another.

For more information including additional text and some detailed links
see the "Late Binding in Microsoft Access" page at
http://www.granite.ab.ca/access/latebinding.htm

Tony
 
C

Cyberwolf0000 via AccessMonster.com

Public Function SendMail(DisplayMsg As Boolean, strTo As String, strSubject
As String, strBody As String, strAttachPathFile As String, Optional strCC As
String, Optional strBCC As String)


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

'Add "To" recipient
'Set objOutlookRecip = .Recipients.Add(strTo)
'objOutlookRecip.Type = olTo
.To = strTo

'"Add "CC" recipient
If strCC <> "" Then
' Set objOutlookRecip = .Recipients.Add(strCC)
' objOutlookRecip.Type = olCC
.CC = strCC
End If

'Add "BCC" recipient
If strBCC <> "" Then
' Set objOutlookRecip = .Recipients.Add(strBCC)
' objOutlookRecip.Type = olBCC
BCC = strBCC
End If

'Add subject, body, and importance of the E-Mail Messzage
.Subject = strSubject
.Body = strBody
.Importance = olImportanceNormal

'Add Attachment
If strAttachPathFile <> "" Then
' Set objOutlookAttach = .Attachments.Add(strAttachPathFile)
.Attachments = strAttachPathFile
End If

'For Each objOutlookRecip In .Recipients
' objOutlookRecip.Resolve
' If Not objOutlookRecip.Resolve Then
' objOutlookMsg.Display
' End If
'Next objOutlookRecip

.Send
End With

Set objOutlookMsg = Nothing
Set objOutlook = Nothing

End Function


Chris said:
There is no code posted below. I'm workign on the same process right now, and
have no error, so I would like to see your code.
[quoted text clipped - 15 lines]

--
James B Gaylord
For the Wolf comes the strength of the Pack,
For the Pack comes the strength of the Wolf,
-R. Kipling
Office 2003 on Win XP SP2
 
C

Cyberwolf0000 via AccessMonster.com

We deployed Exchange/Outlook yesterday. I have had a chance to test it as
thoroughly as I would have liked. I am still confused ove this whole late vs
early binding. Is there other references you can point me to so I can get a
better understandning. I noticed that some of the PC's here are on
Outlook2007 and others are on 2003. Hence the need for the late binding.

TIA<
You shouldn't need the Office 12 object library so I'd remove that.

Do the users already have Outlook 2007 deployed? Or some of them?
Consider switching your code to late binding once you have the code
running smoothly. This would then allow you to remove the reference
the Outlook so your app will execute correctly even if some users
don't yet have Outlook installed.

Also, in the future, your code will still work should some systems be
converted to the next version of Outlook and some are still at the
current version.

Late binding means you can safely remove the reference and only have
an error when the app executes lines of code in question. Rather than
erroring out while starting up the app and not allowing the users in
the app at all. Or when hitting a mid, left or trim function call.

This also is very useful when you don't know version of the external
application will reside on the target system. Or if your organization
is in the middle of moving from one version to another.

For more information including additional text and some detailed links
see the "Late Binding in Microsoft Access" page at
http://www.granite.ab.ca/access/latebinding.htm

Tony

--
James B Gaylord
For the Wolf comes the strength of the Pack,
For the Pack comes the strength of the Wolf,
-R. Kipling
Office 2003 on Win XP SP2
 
T

Tony Toews [MVP]

Cyberwolf0000 via AccessMonster.com said:
We deployed Exchange/Outlook yesterday. I have had a chance to test it as
thoroughly as I would have liked. I am still confused ove this whole late vs
early binding. Is there other references you can point me to so I can get a
better understandning. I noticed that some of the PC's here are on
Outlook2007 and others are on 2003. Hence the need for the late binding.

No, I don't have any other references.

What are your questions? Ask away.

Tony
 
C

Cyberwolf0000 via AccessMonster.com

Sorry for getting back to you so late. I was out of the office for a few
days. I got the whole late vs early binding worked.
I now need to get it set up so that it always sends from the same account.
They want this process to send via a service account so we can more easily
track them. I read something on send on behaveof, but I don't think this is
what I am looking for. If I read it correctly the sent message will not
actually show in the sentonbehaveofs sent box.

Is there a way to actually using a set of credentials besides your own to
send an email from outlook.
Tony said:
No, I don't have any other references.

What are your questions? Ask away.

Tony

--
James B Gaylord
For the Wolf comes the strength of the Pack,
For the Pack comes the strength of the Wolf,
-R. Kipling
Office 2003 on Win XP SP2
 
T

Tony Toews [MVP]

Cyberwolf0000 via AccessMonster.com said:
Sorry for getting back to you so late. I was out of the office for a few
days. I got the whole late vs early binding worked.
I now need to get it set up so that it always sends from the same account.
They want this process to send via a service account so we can more easily
track them. I read something on send on behaveof, but I don't think this is
what I am looking for. If I read it correctly the sent message will not
actually show in the sentonbehaveofs sent box.

All I can suggest is try it yourself. I don't know too much about
Outlooks quirks so I'd then suggest asking in an Outlook newsgroup.

Tony
 

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