emailing

G

Guest

Hello,

I have created a button on a switchboard, I'm trying to set up Access to
send an email to 3 users once a form request has been completed.

thank as always for your help.
 
G

Guest

Thank you,

I did however get stuck, I'm getting the error:
Complie Error
Expected: End of Statment

the error highlighted content is:
Sub SendMessage(Optional AttachmentPath)

thank you for all your help.

O' i noticed to the linked site it says outlook 9.0 object library. i have
object 11.0 library. could that be the reson for the problem? again thank
you.
 
P

Pete D.

Sub SendMessage(Optional AttachmentPath)
Only use this if attachment is in a different location than the datafile.
Attachment path is passed in as an option when you call the sub. Else see
below.

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If
 
P

Pete D.

just delete the word optional, that is because this is a sample and they
want you to know it is an option, the outlook object is looking for one item
only which is the Attachment created when you call the sub at the very
beginning not the word optional..
 
G

Guest

Okay. thank you.

I've removed it and tested it again. now I'm getting an error but nothing is
hightlighed so i'm not able to see where the problem is.

the error reads as:
Compile Error
Argument not optional
 
P

Pete D.

Post your complete code that you have as it is a sample you will have
errors, but hey I had to learn too. Pete D,
 
G

Guest

You are both patient and kind thank you.
the code reads as:

Option Compare Database
Option Explicit

Sub SendMessage(AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
objOutlookRecip.Type = olCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "Last test - I promise." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
 
P

Pete D.

You remove wrong optional, Without Optional prior to AttachmentPath you must
supply the the path in the first line of your code.
Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
 
G

Guest

okay I've added the line of code as you've stated and now the line just below
it is giving me an error that states:
Complie Error:
Argument not optional.

because of my lack of knowldge in code where would you recommed i start in
my learning process.

again thank you for your patience and help.
 
P

Pete D.

Humm, the copy you sent me compiles fine. Post what you currently have one
more time please.
 
G

Guest

I'm sure it's something that i'm doing wrong...
here is the code as i have it.

Option Compare Database
Option Explicit

Sub SendMessage(DisplayMsg As Boolean, Optional AttachmentPath)
Dim objOutlook As Outlook.Application
Dim objOutlookMsg As Outlook.MailItem
Dim objOutlookRecip As Outlook.Recipient
Dim objOutlookAttach As Outlook.Attachment

' Create the Outlook session.
Set objOutlook = CreateObject("Outlook.Application")

' Create the message.
Set objOutlookMsg = objOutlook.CreateItem(olMailItem)

With objOutlookMsg
' Add the To recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Nancy Davolio")
objOutlookRecip.Type = olTo

' Add the CC recipient(s) to the message.
Set objOutlookRecip = .Recipients.Add("Andrew Fuller")
objOutlookRecip.Type = olCC

' Set the Subject, Body, and Importance of the message.
.Subject = "This is an Automation test with Microsoft Outlook"
.Body = "Last test - I promise." & vbCrLf & vbCrLf
.Importance = olImportanceHigh 'High importance

' Add attachments to the message.
If Not IsMissing(AttachmentPath) Then
Set objOutlookAttach = .Attachments.Add(AttachmentPath)
End If

' Resolve each Recipient's name.
For Each objOutlookRecip In .Recipients
objOutlookRecip.Resolve
If Not objOutlookRecip.Resolve Then
objOutlookMsg.Display
End If
Next
.Send

End With
Set objOutlookMsg = Nothing
Set objOutlook = Nothing
End Sub
 
P

Pete D.

No it isn't your fault, I went and looked at the original code verses the
one I had which has been extensively modified. Remove the this portion in
beginning
DisplayMsg As Boolean, and don't forget to remove the "," I had an option
in my code to display the message for editing before sending it. Boolean is
Yes/No. Sorry about that and I've been out for awhile so sorry it took so
long to get back to you.
 
G

Guest

NO probelm, besides i know i'm not the only one bugging you.

i've removed that line of code and i'm not getting this error while i complie.

Complie error:
user-defined trype not defined.

the highlighted code with this error is:
Dim objOutlook As Outlook.Application
 
P

Pete D.

Okay, send me a list of your references. When in the debug window click
tools references. Send me the list. Pete
 
G

Guest

The selected references are:

Visual Basic For Applications
Microsft Access 11.0 Object Library
OLE Automation
Microsfoft DAO 3.6 Object Library
Microsfoft ActiveX Data Objects 2.1 Library
Microsfoft Calendar Control 11.0
Microsfoft Windows Common Controls-2 6.0 (SP4)
Microsfoft Windows Common Controls 6.0 (SP6)

everything else in the listing is unchecked/unselected.
 
P

Pete D.

Okay, write down what every you remove before removing it so you can go
back. Remove Microsoft Windows Common Controls-2 6.0 (SP4) and compile
again.
 
G

Guest

Sadly I'm getting the same error after removing it.

Complie Error:
user-defined trype not defined.
 

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