Sending Email using Code

L

Linda Ribbach

Hi,
When the dates are the same, it still sends the email. I only want an email when there is no match. What did I do wrong?

Private Sub Form_Load()
Dim db As Database
Dim rec1 As Recordset
Dim rec2 As Recordset
Set db = CurrentDb
Set rec1 = db.OpenRecordset("tblRunLog")
Set rec2 = db.OpenRecordset("tblRidCountLog")
rec1.MoveLast
rec2.MoveLast
If rec1![RunDate] <> rec2![ImportDate] Then
DoCmd.SendObject acForm, "frmRunLog", "MS-DOSText(*.txt)", "(e-mail address removed)", "(e-mail address removed)", "", "Daily Org Request Run", "There was no data for this date", False, ""

End If
rec1.Close
rec2.Close
db.Close
Set db = Nothing
DocName = "frmRunlog"
DoCmd.Close A_FORM, "frmRunLog"
End Sub


Thanks in advance.

Linda
 
C

Cheryl Fischer

Wild guess... Is it possible that your RunDate and/or ImportDate fields
are formatted as general and include time as well as date values? That
could make them evaluate as not equal even when the dates are the same.

If this is true you might want to code your expression as follows:

If DateValue(rec1![RunDate]) <> DateValue(rec2![ImportDate]) Then


hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Linda Ribbach said:
Hi,
When the dates are the same, it still sends the email. I only want an
email when there is no match. What did I do wrong?
Private Sub Form_Load()
Dim db As Database
Dim rec1 As Recordset
Dim rec2 As Recordset
Set db = CurrentDb
Set rec1 = db.OpenRecordset("tblRunLog")
Set rec2 = db.OpenRecordset("tblRidCountLog")
rec1.MoveLast
rec2.MoveLast
If rec1![RunDate] <> rec2![ImportDate] Then
DoCmd.SendObject acForm, "frmRunLog", "MS-DOSText(*.txt)",
"(e-mail address removed)", "(e-mail address removed)", "", "Daily Org Request Run", "There
was no data for this date", False, ""
 
P

Patrick

Cheryl: how do you stop the following message from
Happening when you execute the following code:

DoCmd.SendObject
acForm, "testform1", , "(e-mail address removed)", , _
"", "Daily Org Request Run", "There was no data for this
date", False

Mesg error: "A program is trying to automatically send e-
mail on your behalf. Do you want to allow this? Yes or NO"

Thanks in advance for your help,
PAtrick
-----Original Message-----
Wild guess... Is it possible that your RunDate and/or ImportDate fields
are formatted as general and include time as well as date values? That
could make them evaluate as not equal even when the dates are the same.

If this is true you might want to code your expression as follows:

If DateValue(rec1![RunDate]) <> DateValue(rec2! [ImportDate]) Then


hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Hi,
When the dates are the same, it still sends the email.
I only want an
email when there is no match. What did I do wrong?
Private Sub Form_Load()
Dim db As Database
Dim rec1 As Recordset
Dim rec2 As Recordset
Set db = CurrentDb
Set rec1 = db.OpenRecordset("tblRunLog")
Set rec2 = db.OpenRecordset("tblRidCountLog")
rec1.MoveLast
rec2.MoveLast
If rec1![RunDate] <> rec2![ImportDate] Then
DoCmd.SendObject acForm, "frmRunLog", "MS-
DOSText(*.txt)",
"(e-mail address removed)", "(e-mail address removed)", "", "Daily Org Request Run", "There
was no data for this date", False, ""
End If
rec1.Close
rec2.Close
db.Close
Set db = Nothing
DocName = "frmRunlog"
DoCmd.Close A_FORM, "frmRunLog"
End Sub


Thanks in advance.

Linda


.
 
C

Cheryl Fischer

These messages are the result of increased security for Outlook which is
built-in and, unless you are working in an Exchange environment, cannot be
turned off. For more information, see:
http://www.outlookcode.com/d/sec.htm

To work around this feature, I have been pleased with Express
Soft's free utility called "ClickYes", available for download at:
http://www.express-soft.com/mailmate/clickyes.html. It does not make the
security prompt go away, but it does use api calls to click the 'Yes' button
for you.

Here is a link to a thread where you can find code that will check to see
whether ClickYes is running, start the utility, run email-related code, and
then turn the utility off.

http://tinyurl.com/3x3xj

ClickYes is not the only work-around or option available; others can be
found at: http://www.outlookcode.com/d/sec.htm

hth,

--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Patrick said:
Cheryl: how do you stop the following message from
Happening when you execute the following code:

DoCmd.SendObject
acForm, "testform1", , "(e-mail address removed)", , _
"", "Daily Org Request Run", "There was no data for this
date", False

Mesg error: "A program is trying to automatically send e-
mail on your behalf. Do you want to allow this? Yes or NO"

Thanks in advance for your help,
PAtrick
-----Original Message-----
Wild guess... Is it possible that your RunDate and/or ImportDate fields
are formatted as general and include time as well as date values? That
could make them evaluate as not equal even when the dates are the same.

If this is true you might want to code your expression as follows:

If DateValue(rec1![RunDate]) <> DateValue(rec2! [ImportDate]) Then


hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Hi,
When the dates are the same, it still sends the email.
I only want an
email when there is no match. What did I do wrong?
Private Sub Form_Load()
Dim db As Database
Dim rec1 As Recordset
Dim rec2 As Recordset
Set db = CurrentDb
Set rec1 = db.OpenRecordset("tblRunLog")
Set rec2 = db.OpenRecordset("tblRidCountLog")
rec1.MoveLast
rec2.MoveLast
If rec1![RunDate] <> rec2![ImportDate] Then
DoCmd.SendObject acForm, "frmRunLog", "MS-
DOSText(*.txt)",
"(e-mail address removed)", "(e-mail address removed)", "", "Daily Org Request Run", "There
was no data for this date", False, ""
End If
rec1.Close
rec2.Close
db.Close
Set db = Nothing
DocName = "frmRunlog"
DoCmd.Close A_FORM, "frmRunLog"
End Sub


Thanks in advance.

Linda


.
 
P

Patrick

thanks a million!!
-----Original Message-----

These messages are the result of increased security for Outlook which is
built-in and, unless you are working in an Exchange environment, cannot be
turned off. For more information, see:
http://www.outlookcode.com/d/sec.htm

To work around this feature, I have been pleased with Express
Soft's free utility called "ClickYes", available for download at:
http://www.express-soft.com/mailmate/clickyes.html. It does not make the
security prompt go away, but it does use api calls to click the 'Yes' button
for you.

Here is a link to a thread where you can find code that will check to see
whether ClickYes is running, start the utility, run email- related code, and
then turn the utility off.

http://tinyurl.com/3x3xj

ClickYes is not the only work-around or option available; others can be
found at: http://www.outlookcode.com/d/sec.htm

hth,

--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Cheryl: how do you stop the following message from
Happening when you execute the following code:

DoCmd.SendObject
acForm, "testform1", , "(e-mail address removed)", , _
"", "Daily Org Request Run", "There was no data for this
date", False

Mesg error: "A program is trying to automatically send e-
mail on your behalf. Do you want to allow this? Yes or NO"

Thanks in advance for your help,
PAtrick
-----Original Message-----
Wild guess... Is it possible that your RunDate and/or ImportDate fields
are formatted as general and include time as well as
date
values? That
could make them evaluate as not equal even when the
dates
are the same.
If this is true you might want to code your expression
as
follows:
If DateValue(rec1![RunDate]) <> DateValue(rec2! [ImportDate]) Then


hth,
--

Cheryl Fischer, MVP Microsoft Access
Law/Sys Associates, Houston, TX


Hi,
When the dates are the same, it still sends the
email.
I only want an
email when there is no match. What did I do wrong?

Private Sub Form_Load()
Dim db As Database
Dim rec1 As Recordset
Dim rec2 As Recordset
Set db = CurrentDb
Set rec1 = db.OpenRecordset("tblRunLog")
Set rec2 = db.OpenRecordset("tblRidCountLog")
rec1.MoveLast
rec2.MoveLast
If rec1![RunDate] <> rec2![ImportDate] Then
DoCmd.SendObject acForm, "frmRunLog", "MS- DOSText(*.txt)",
"(e-mail address removed)", "(e-mail address removed)", "", "Daily Org Request Run", "There
was no data for this date", False, ""

End If
rec1.Close
rec2.Close
db.Close
Set db = Nothing
DocName = "frmRunlog"
DoCmd.Close A_FORM, "frmRunLog"
End Sub


Thanks in advance.

Linda



.


.
 

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