VBA Code to send email with attachments

D

Denise

I am trying to use a button to send email with attachments
to different people all the time. Below is the code I am
using so far and I have two problems.

One is that I cannot get it to use an email address in my
Tblcontacts, field is named Email. Anyone know what I am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
 
C

Cheryl Fischer

Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are passing a literal string
value. When I run similar email routines from a form, I have the email
address field bound to a control on the form. Then, strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the Outlook Security Prompt
and, unless you are working in an environment where Microsoft Exchange is
used and your Exchange administrator is willing to apply some "fixes", you
are going to see this message. There are a number of work-arounds ( use
the free utility ExpressClickYes with code provided at their website ), and
these are described more fully by Outlook MVP Sue Mosher, as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application tries to access
certain Outlook properties and methods are designed to inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If you are a standalone
user, Outlook provides no way to suppress this behavior. However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to click the security
dialog buttons automatically. Beware that this means if a virus tries to
send mail using Outlook or gain access to your address book, it will
succeed.

"If you're the administrator in an Exchange Server environment, you can
reduce the impact of the security prompts with administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use one of these
approaches to redo the program:

-- Use Extended MAPI (see http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only one that Microsoft
recommendeds.

-- Use Redemption (http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but parallels the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec for a link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) tool to start suspended
and turn it on only when your program needs to have the buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Denise said:
I am trying to use a button to send email with attachments
to different people all the time. Below is the code I am
using so far and I have two problems.

One is that I cannot get it to use an email address in my
Tblcontacts, field is named Email. Anyone know what I am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
 
C

Cheryl Fischer

The following appears to be an instruction - but it is not:
There are a number of work-arounds ( use the free utility ExpressClickYes
with code provided at their website ),

I *meant* to say:

" *I* use the free utility ExpressClickYes with code provided at their
website )",


--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Denise said:
I am trying to use a button to send email with attachments
to different people all the time. Below is the code I am
using so far and I have two problems.

One is that I cannot get it to use an email address in my
Tblcontacts, field is named Email. Anyone know what I am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing
 
G

Guest

Thank you that worked! I am looking into the outlook
message with our Exchange person.

I have another question now that this works. I also want
to attached a report from Access in Microsoft Word format
to this code but can't get it to attach. I have added an
the following code:

strattachment3 = Report.Confirmation
"Confirmation is the name of the report in Access"

Thank you for your help.
-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are passing a literal string
value. When I run similar email routines from a form, I have the email
address field bound to a control on the form. Then, strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the Outlook Security Prompt
and, unless you are working in an environment where Microsoft Exchange is
used and your Exchange administrator is willing to apply some "fixes", you
are going to see this message. There are a number of work-arounds ( use
the free utility ExpressClickYes with code provided at their website ), and
these are described more fully by Outlook MVP Sue Mosher, as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application tries to access
certain Outlook properties and methods are designed to inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If you are a standalone
user, Outlook provides no way to suppress this behavior. However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to click the security
dialog buttons automatically. Beware that this means if a virus tries to
send mail using Outlook or gain access to your address book, it will
succeed.

"If you're the administrator in an Exchange Server environment, you can
reduce the impact of the security prompts with administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but parallels the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec for a link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) tool to start suspended
and turn it on only when your program needs to have the buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

I am trying to use a button to send email with attachments
to different people all the time. Below is the code I am
using so far and I have two problems.

One is that I cannot get it to use an email address in my
Tblcontacts, field is named Email. Anyone know what I am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing


.
 
C

Cheryl Fischer

You cannot attach the Report Object directly; you'll need to export it to an
RTF type file (or PDF if you do not need editing capability but do need all
formatting) and then attach that file to the email.

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Thank you that worked! I am looking into the outlook
message with our Exchange person.

I have another question now that this works. I also want
to attached a report from Access in Microsoft Word format
to this code but can't get it to attach. I have added an
the following code:

strattachment3 = Report.Confirmation
"Confirmation is the name of the report in Access"

Thank you for your help.
-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are passing a literal string
value. When I run similar email routines from a form, I have the email
address field bound to a control on the form. Then, strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the Outlook Security Prompt
and, unless you are working in an environment where Microsoft Exchange is
used and your Exchange administrator is willing to apply some "fixes", you
are going to see this message. There are a number of work-arounds ( use
the free utility ExpressClickYes with code provided at their website ), and
these are described more fully by Outlook MVP Sue Mosher, as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application tries to access
certain Outlook properties and methods are designed to inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If you are a standalone
user, Outlook provides no way to suppress this behavior. However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to click the security
dialog buttons automatically. Beware that this means if a virus tries to
send mail using Outlook or gain access to your address book, it will
succeed.

"If you're the administrator in an Exchange Server environment, you can
reduce the impact of the security prompts with administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but parallels the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec for a link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) tool to start suspended
and turn it on only when your program needs to have the buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

I am trying to use a button to send email with attachments
to different people all the time. Below is the code I am
using so far and I have two problems.

One is that I cannot get it to use an email address in my
Tblcontacts, field is named Email. Anyone know what I am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing


.
 
G

Guest

Also, can you do all this and not send the email...just
have it pop up so that you can hit send yourself.
Sometimes when we send these attachments we have something
additional that needs to be added into the email which is
why I want this to do everything below but do not send
automatically.

I hope I am clear.

Thank you again!!!

-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are passing a literal string
value. When I run similar email routines from a form, I have the email
address field bound to a control on the form. Then, strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the Outlook Security Prompt
and, unless you are working in an environment where Microsoft Exchange is
used and your Exchange administrator is willing to apply some "fixes", you
are going to see this message. There are a number of work-arounds ( use
the free utility ExpressClickYes with code provided at their website ), and
these are described more fully by Outlook MVP Sue Mosher, as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application tries to access
certain Outlook properties and methods are designed to inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If you are a standalone
user, Outlook provides no way to suppress this behavior. However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to click the security
dialog buttons automatically. Beware that this means if a virus tries to
send mail using Outlook or gain access to your address book, it will
succeed.

"If you're the administrator in an Exchange Server environment, you can
reduce the impact of the security prompts with administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but parallels the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec for a link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) tool to start suspended
and turn it on only when your program needs to have the buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

I am trying to use a button to send email with attachments
to different people all the time. Below is the code I am
using so far and I have two problems.

One is that I cannot get it to use an email address in my
Tblcontacts, field is named Email. Anyone know what I am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing


.
 
C

Cheryl Fischer

Try replacing this:

olMail.Send

with this:

olMail.Display



hth,
--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Also, can you do all this and not send the email...just
have it pop up so that you can hit send yourself.
Sometimes when we send these attachments we have something
additional that needs to be added into the email which is
why I want this to do everything below but do not send
automatically.

I hope I am clear.

Thank you again!!!

-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are passing a literal string
value. When I run similar email routines from a form, I have the email
address field bound to a control on the form. Then, strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the Outlook Security Prompt
and, unless you are working in an environment where Microsoft Exchange is
used and your Exchange administrator is willing to apply some "fixes", you
are going to see this message. There are a number of work-arounds ( use
the free utility ExpressClickYes with code provided at their website ), and
these are described more fully by Outlook MVP Sue Mosher, as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application tries to access
certain Outlook properties and methods are designed to inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If you are a standalone
user, Outlook provides no way to suppress this behavior. However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to click the security
dialog buttons automatically. Beware that this means if a virus tries to
send mail using Outlook or gain access to your address book, it will
succeed.

"If you're the administrator in an Exchange Server environment, you can
reduce the impact of the security prompts with administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but parallels the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec for a link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) tool to start suspended
and turn it on only when your program needs to have the buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

I am trying to use a button to send email with attachments
to different people all the time. Below is the code I am
using so far and I have two problems.

One is that I cannot get it to use an email address in my
Tblcontacts, field is named Email. Anyone know what I am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing


.
 
D

Denise

Thank you so much for your help!

Denise
-----Original Message-----
Try replacing this:

olMail.Send

with this:

olMail.Display



hth,
--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Also, can you do all this and not send the email...just
have it pop up so that you can hit send yourself.
Sometimes when we send these attachments we have something
additional that needs to be added into the email which is
why I want this to do everything below but do not send
automatically.

I hope I am clear.

Thank you again!!!

-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are passing a literal string
value. When I run similar email routines from a form,
I
have the email
address field bound to a control on the form. Then, strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the
Outlook
Security Prompt
and, unless you are working in an environment where Microsoft Exchange is
used and your Exchange administrator is willing to
apply
some "fixes", you
are going to see this message. There are a number of work-arounds ( use
the free utility ExpressClickYes with code provided at their website ), and
these are described more fully by Outlook MVP Sue
Mosher,
as follows:
BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application tries to access
certain Outlook properties and methods are designed to inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If you are a standalone
user, Outlook provides no way to suppress this
behavior.
However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to click the security
dialog buttons automatically. Beware that this means
if a
virus tries to
send mail using Outlook or gain access to your address book, it will
succeed.

"If you're the administrator in an Exchange Server environment, you can
reduce the impact of the security prompts with administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but
parallels
the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec
for a
link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html)
tool
to start suspended
and turn it on only when your program needs to have the buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

I am trying to use a button to send email with attachments
to different people all the time. Below is the code
I
am
using so far and I have two problems.

One is that I cannot get it to use an email address
in
my
Tblcontacts, field is named Email. Anyone know what
I
am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click
yes
or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing




.


.
 
C

Cheryl Fischer

You're welcome, Denise.

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Denise said:
Thank you so much for your help!

Denise
-----Original Message-----
Try replacing this:

olMail.Send

with this:

olMail.Display



hth,
--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Also, can you do all this and not send the email...just
have it pop up so that you can hit send yourself.
Sometimes when we send these attachments we have something
additional that needs to be added into the email which is
why I want this to do everything below but do not send
automatically.

I hope I am clear.

Thank you again!!!


-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are
passing a literal string
value. When I run similar email routines from a form, I
have the email
address field bound to a control on the form. Then,
strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the Outlook
Security Prompt
and, unless you are working in an environment where
Microsoft Exchange is
used and your Exchange administrator is willing to apply
some "fixes", you
are going to see this message. There are a number of
work-arounds ( use
the free utility ExpressClickYes with code provided at
their website ), and
these are described more fully by Outlook MVP Sue Mosher,
as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application
tries to access
certain Outlook properties and methods are designed to
inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If
you are a standalone
user, Outlook provides no way to suppress this behavior.
However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to
click the security
dialog buttons automatically. Beware that this means if a
virus tries to
send mail using Outlook or gain access to your address
book, it will
succeed.

"If you're the administrator in an Exchange Server
environment, you can
reduce the impact of the security prompts with
administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use
one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only
one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but parallels
the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the
security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec for a
link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) tool
to start suspended
and turn it on only when your program needs to have the
buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

message
I am trying to use a button to send email with
attachments
to different people all the time. Below is the code I
am
using so far and I have two problems.

One is that I cannot get it to use an email address in
my
Tblcontacts, field is named Email. Anyone know what I
am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes
or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing




.


.
 
D

Denise

Now, I have been unable to export the report object so
that I can attach it to the email. Can you explain how to
do this....I tried Transfertext...sorry to keep bothering
you, I am new at all this and not good at VBA yet.

Thanks again,

Denise
-----Original Message-----
You cannot attach the Report Object directly; you'll need to export it to an
RTF type file (or PDF if you do not need editing capability but do need all
formatting) and then attach that file to the email.

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Thank you that worked! I am looking into the outlook
message with our Exchange person.

I have another question now that this works. I also want
to attached a report from Access in Microsoft Word format
to this code but can't get it to attach. I have added an
the following code:

strattachment3 = Report.Confirmation
"Confirmation is the name of the report in Access"

Thank you for your help.
-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are passing a literal string
value. When I run similar email routines from a form,
I
have the email
address field bound to a control on the form. Then, strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the
Outlook
Security Prompt
and, unless you are working in an environment where Microsoft Exchange is
used and your Exchange administrator is willing to
apply
some "fixes", you
are going to see this message. There are a number of work-arounds ( use
the free utility ExpressClickYes with code provided at their website ), and
these are described more fully by Outlook MVP Sue
Mosher,
as follows:
BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application tries to access
certain Outlook properties and methods are designed to inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If you are a standalone
user, Outlook provides no way to suppress this
behavior.
However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to click the security
dialog buttons automatically. Beware that this means
if a
virus tries to
send mail using Outlook or gain access to your address book, it will
succeed.

"If you're the administrator in an Exchange Server environment, you can
reduce the impact of the security prompts with administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but
parallels
the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec
for a
link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html)
tool
to start suspended
and turn it on only when your program needs to have the buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

I am trying to use a button to send email with attachments
to different people all the time. Below is the code
I
am
using so far and I have two problems.

One is that I cannot get it to use an email address
in
my
Tblcontacts, field is named Email. Anyone know what
I
am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click
yes
or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing




.


.
 
C

Cheryl Fischer

Well, TransferText creates a text file and that's not what you want.

Here is an example using the OutPutTo method:

DoCmd.OutputTo acOutputReport, "rptMyReport", _
acFormatRTF, "MyReportDocument.rtf"

There are number of options available with the OutputTo method and you
should take a look at them using VBA Help.


--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Denise said:
Now, I have been unable to export the report object so
that I can attach it to the email. Can you explain how to
do this....I tried Transfertext...sorry to keep bothering
you, I am new at all this and not good at VBA yet.

Thanks again,

Denise
-----Original Message-----
You cannot attach the Report Object directly; you'll need to export it to an
RTF type file (or PDF if you do not need editing capability but do need all
formatting) and then attach that file to the email.

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Thank you that worked! I am looking into the outlook
message with our Exchange person.

I have another question now that this works. I also want
to attached a report from Access in Microsoft Word format
to this code but can't get it to attach. I have added an
the following code:

strattachment3 = Report.Confirmation
"Confirmation is the name of the report in Access"

Thank you for your help.

-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are
passing a literal string
value. When I run similar email routines from a form, I
have the email
address field bound to a control on the form. Then,
strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the Outlook
Security Prompt
and, unless you are working in an environment where
Microsoft Exchange is
used and your Exchange administrator is willing to apply
some "fixes", you
are going to see this message. There are a number of
work-arounds ( use
the free utility ExpressClickYes with code provided at
their website ), and
these are described more fully by Outlook MVP Sue Mosher,
as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application
tries to access
certain Outlook properties and methods are designed to
inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If
you are a standalone
user, Outlook provides no way to suppress this behavior.
However, you can
use a free tool called Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) to
click the security
dialog buttons automatically. Beware that this means if a
virus tries to
send mail using Outlook or gain access to your address
book, it will
succeed.

"If you're the administrator in an Exchange Server
environment, you can
reduce the impact of the security prompts with
administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use
one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only
one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but parallels
the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the
security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec for a
link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) tool
to start suspended
and turn it on only when your program needs to have the
buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

message
I am trying to use a button to send email with
attachments
to different people all the time. Below is the code I
am
using so far and I have two problems.

One is that I cannot get it to use an email address in
my
Tblcontacts, field is named Email. Anyone know what I
am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes
or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing




.


.
 
D

Denise

It all worked great. I have everything I need. This is
the first time I have got a response from this newsgroup
and I really really appreciate the help.

Thank you.
Denise
-----Original Message-----
Well, TransferText creates a text file and that's not what you want.

Here is an example using the OutPutTo method:

DoCmd.OutputTo acOutputReport, "rptMyReport", _
acFormatRTF, "MyReportDocument.rtf"

There are number of options available with the OutputTo method and you
should take a look at them using VBA Help.


--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Now, I have been unable to export the report object so
that I can attach it to the email. Can you explain how to
do this....I tried Transfertext...sorry to keep bothering
you, I am new at all this and not good at VBA yet.

Thanks again,

Denise
-----Original Message-----
You cannot attach the Report Object directly; you'll
need
to export it to an
RTF type file (or PDF if you do not need editing capability but do need all
formatting) and then attach that file to the email.

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Thank you that worked! I am looking into the outlook
message with our Exchange person.

I have another question now that this works. I also want
to attached a report from Access in Microsoft Word format
to this code but can't get it to attach. I have
added
an
the following code:

strattachment3 = Report.Confirmation
"Confirmation is the name of the report in Access"

Thank you for your help.

-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are
passing a literal string
value. When I run similar email routines from a
form,
I
have the email
address field bound to a control on the form. Then,
strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the Outlook
Security Prompt
and, unless you are working in an environment where
Microsoft Exchange is
used and your Exchange administrator is willing to apply
some "fixes", you
are going to see this message. There are a number of
work-arounds ( use
the free utility ExpressClickYes with code provided at
their website ), and
these are described more fully by Outlook MVP Sue Mosher,
as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application
tries to access
certain Outlook properties and methods are designed to
inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If
you are a standalone
user, Outlook provides no way to suppress this behavior.
However, you can
use a free tool called Express ClickYes
(http://www.express- soft.com/mailmate/clickyes.html) to
click the security
dialog buttons automatically. Beware that this means if a
virus tries to
send mail using Outlook or gain access to your address
book, it will
succeed.

"If you're the administrator in an Exchange Server
environment, you can
reduce the impact of the security prompts with
administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use
one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only
one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but parallels
the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the
security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec for a
link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html) tool
to start suspended
and turn it on only when your program needs to have the
buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

message
I am trying to use a button to send email with
attachments
to different people all the time. Below is the
code
I
am
using so far and I have two problems.

One is that I cannot get it to use an email
address
in
my
Tblcontacts, field is named Email. Anyone know
what
I
am
doing wrong?

Second, I keep getting a message from Microsoft Outlook
saying I am sending an email and you have to click yes
or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject ("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing




.



.


.
 
C

Cheryl Fischer

You're welcome - glad to hear it!

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Denise said:
It all worked great. I have everything I need. This is
the first time I have got a response from this newsgroup
and I really really appreciate the help.

Thank you.
Denise
-----Original Message-----
Well, TransferText creates a text file and that's not what you want.

Here is an example using the OutPutTo method:

DoCmd.OutputTo acOutputReport, "rptMyReport", _
acFormatRTF, "MyReportDocument.rtf"

There are number of options available with the OutputTo method and you
should take a look at them using VBA Help.


--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Now, I have been unable to export the report object so
that I can attach it to the email. Can you explain how to
do this....I tried Transfertext...sorry to keep bothering
you, I am new at all this and not good at VBA yet.

Thanks again,

Denise

-----Original Message-----
You cannot attach the Report Object directly; you'll need
to export it to an
RTF type file (or PDF if you do not need editing
capability but do need all
formatting) and then attach that file to the email.

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

Thank you that worked! I am looking into the outlook
message with our Exchange person.

I have another question now that this works. I also
want
to attached a report from Access in Microsoft Word
format
to this code but can't get it to attach. I have added
an
the following code:

strattachment3 = Report.Confirmation
"Confirmation is the name of the report in Access"

Thank you for your help.

-----Original Message-----
Denise,

I think the problem may be with this line:

strTo = "([TblContact.Email])"

With quotation marks around the expression, you are
passing a literal string
value. When I run similar email routines from a form,
I
have the email
address field bound to a control on the form. Then,
strTo receives the
value of the control on the form:

strTo = Me!MyEmailField

Give the above a try and post back with your results.

As to the message you are receiving, this is the
Outlook
Security Prompt
and, unless you are working in an environment where
Microsoft Exchange is
used and your Exchange administrator is willing to
apply
some "fixes", you
are going to see this message. There are a number of
work-arounds ( use
the free utility ExpressClickYes with code provided at
their website ), and
these are described more fully by Outlook MVP Sue
Mosher,
as follows:

BEGIN QUOTED MATERIAL:

"The security dialogs that pop up when an application
tries to access
certain Outlook properties and methods are designed to
inhibit the spread of
viruses via Outlook; see
http://www.slipstick.com/outlook/esecup.htm#autosec. If
you are a standalone
user, Outlook provides no way to suppress this
behavior.
However, you can
use a free tool called Express ClickYes
(http://www.express- soft.com/mailmate/clickyes.html) to
click the security
dialog buttons automatically. Beware that this means
if a
virus tries to
send mail using Outlook or gain access to your address
book, it will
succeed.

"If you're the administrator in an Exchange Server
environment, you can
reduce the impact of the security prompts with
administrative tools. See
http://www.slipstick.com/outlook/esecup/admin.htm

"If it's an application you wrote yourself, you can use
one of these
approaches to redo the program:

-- Use Extended MAPI (see
http://www.slipstick.com/dev/mapi.htm) and C++
or Delphi; this is the most secure method and the only
one that Microsoft
recommendeds.

-- Use Redemption
(http://www.dimastr.com/redemption/), a third-party
COM library that wraps around Extended MAPI but
parallels
the Outlook Object
Model

-- Use SendKeys to "click" the buttons on the
security dialogs that your
application may trigger. See
http://www.slipstick.com/outlook/esecup.htm#autosec
for a
link to sample
code.

-- Program the free Express ClickYes
(http://www.express-soft.com/mailmate/clickyes.html)
tool
to start suspended
and turn it on only when your program needs to have the
buttons clicked
automatically."

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at
http://www.slipstick.com
Author of
Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.slipstick.com/books/jumpstart.htm

END OF QUOTED MATERIAL

--
Cheryl Fischer
Law/Sys Associates
Houston, TX

message
I am trying to use a button to send email with
attachments
to different people all the time. Below is the code
I
am
using so far and I have two problems.

One is that I cannot get it to use an email address
in
my
Tblcontacts, field is named Email. Anyone know what
I
am
doing wrong?

Second, I keep getting a message from Microsoft
Outlook
saying I am sending an email and you have to click
yes
or
no and I don't want to do that extra step.

Can anyone help?


Private Sub Command133_Click()

Dim strTo As String
Dim strsubject As String
Dim varbody As Variant
Dim strattachment1 As String
Dim strattachment2 As String

strTo = "([TblContact.Email])"
strsubject = "subject"
varbody = "Attached please find your confirmation"
strattachment1 = "name and location of attachment"
strattachment2 = "name and location of attachment"

Dim olApp As Outlook.Application
Set olApp = CreateObject ("Outlook.Application")

Dim olNs As Outlook.NameSpace
Set olNs = olApp.GetNamespace("MAPI")
olNs.logon

Dim olMail As Outlook.MailItem
Set olMail = olApp.CreateItem(olMailItem)

olMail.To = strTo
olMail.subject = strsubject
olMail.body = varbody

If Len(strattachment1) <> 0 Then
olMail.Attachments.Add (strattachment1)
End If
If Len(strattachment2) <> 0 Then
olMail.Attachments.Add (strattachment2)
End If

olMail.Send

Set olNs = Nothing
Set olMail = Nothing
Set olApp = Nothing




.



.


.
 
T

TC

(snip)
There are a number of work-arounds ( use the free utility
ExpressClickYes with code provided at their website)

How does it look in practice? Are there any nasty flashes, or does it look
fairly seamless?

TC
 
C

Cheryl Fischer

Hello TC,

Well, "seamless" is pretty much a matter of opinion. ClickYes does not make
the Outlook Security Prompt fail to appear or change its operation in any
manner. It simply sends a message to the popup window via API that the
'Yes' button has been clicked. The user sees everything they saw before
installation of ClickYes - they just have to sit back and watch the program
do the mouse clicks - or walk away and let the program do its thing.

So, if the user is sending 150 individual emails, he or she is going to see
the Security prompt 150 times. The Security Prompt and what appears to be
its programmed "wait" before the mouse can be clicked do make the process
slower than before the Security Prompt made all of us have to look at
work-arounds. However, the fact that the utility is free and comes without
a "nag" and that it makes no changes to Outlook security are pluses.

One thing that I found and asked them about was how to make ClickYes close
fully. Their code shows the sample application leaving ClickYes still in
the SysTray but in suspended mode:

' Send the message to Suspend ClickYes
Res = SendMessage(wnd, uClickYes, 0, 0)

They suggested adding the following line:

Res = SendMessage(wnd, WM_DESTROY, 0, 0)

I added it to my routines and found that it worked as described to close
ClickYes completely.
 
T

TC

Ok, thanks for that info.

It related to something else I am doing. I create a Word document through
automation, & make Word visible, so the user can view or edit the document.
But I do not want the user to quite Word, or close the document. This can be
done with a sendkeys trick, where you send an escape character in
anticipation of a dialog box that Word will display. This works "seamlessly"
in the sense that the dialog box is dismissed without appearing on the
screen, at all!

Perhaps if clickyes has a "programmed wait", that would stop it being
"seamless" in that regard.

Cheers,
TC
 

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