AutoExec?

J

jo

Hi I have an AutoExec macro that starts a macro that will create an email and
I only want this to happen once a week. (This is opened by the Schedule
Tasks) But the AutoExec will kick start the email every time the program is
opened by a User. Is there en way I can add code to check if and email has
gone out to not send another one???
Jo
 
S

Stefan Hoffmann

hi Jo,
Hi I have an AutoExec macro that starts a macro that will create an email and
I only want this to happen once a week. (This is opened by the Schedule
Tasks) But the AutoExec will kick start the email every time the program is
opened by a User. Is there en way I can add code to check if and email has
gone out to not send another one???
Yes.

First of all you need to modify your scheduled task. You need to change
the call to your .mdb file to

"C:\pathToMsAccess\MSACCESS.EXE" "C:\pathTo\Database.mdb" /cmd SendEMail

Then you need a function in a standard module:

Public Function SendEMail() As Boolean

'Test the value from the /cmd parameter.
If Command() = "SendEMail" Then
DoCmd.RunMacro "yourMacroName"
End If

End Function

Use this function in your AutoExec macro with then RunCode action.

Now the program will only send the e-mail when started by the scheduled
task.


mfG
--> stefan <--
 
J

jo

Hi Steve I have done the following but i am getting an error Expression you
entered has a function name that Mydatabase can't find? I am doing something
wrong??:

Made a macro called AutoExec; Runcode; Function Name SendEmail()
and the code: Option Compare Database

Public Function SendEMail() As Boolean

'Test the value from the /cmd parameter.
If Command() = "SendEMail" Then
DoCmd.RunMacro "Checker"
End If

End Function
 
K

Klatuu

Using Stefan's method, you do not need the autoexec macro.

The important part is using the command line option he showed you. The /cmd
SendEMail tells Access to run the function named SendEmail.

Also, be sure your function is in a Standard Module and that the function
and the module do not have the same name. If you name a function or sub in a
module the same name as the module, it will cause problems.
 
J

jo

Hi guys thanks for yr replys most appreciated! After reading yr reply I can
understand how important the /cmd SendEmail is but not sure where abouts on
the Scheduler task I put it? I keep getting error:
"The command line you used to start Access contains an option that Microsoft
Office Access doesnt reckonize" . (I have windows vista) . And this is what I
have put in the Action part:
Program Box:
"D:\Central Gauge Calibration Database2.mdb"
Add Argument box:
Menu\Programs\Microsoft Office\MSACCESS.EXE†“C: \Users\Joanne
Blankley\Desktop\Central Gauge Calibration Database2â€/cmd SendEmail

Sorry to be a pain but I am new Schedule Task.
 
J

jo

Hi Rodger thanks the reply, I went on yr blog and found it very helpful, BUT
I am still having problems? Can you point me in the right direction please...

1. "The command line you used to start Microsoft Office Access contains an
option that Microsoft Office Access doesnt reckonize"
Click ok then i get:
2. "The expression you entered has a function name that "Mydatabase" can't
find"

I placed the code in the Modual section and named it SendEMail. I created a
macro to runcode named SendEmail and my code is:

Public Function SendEMail() As Boolean

'Test the value from the /cmd parameter.
If Command() = "SendEMail" Then
DoCmd.RunMacro "Query overdue"
End If

End Function


"
 
J

jo

Hi Rodger just to let you know that I have now solved my problems!! First one
was my path was incorrect and the second I change the last part of the
condition from /x SendEMail to /x checker which is the macro that preforms
the query and sends the email. So I dont use the code that I was given
before.. So thank you and any one reading this Rodger's blog is most helpful!!
Jo
 

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