UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> e-mail a report on month end    
 
   
lillyellen
post Mar 8 2007, 04:58 AM
Post #1

UtterAccess Addict
Posts: 132



I need to e-mail a report at the end of each month. How can I get this done automatically with code?
Go to the top of the page
 
+
Larry Larsen
post Mar 8 2007, 06:36 AM
Post #2

UA Editor + Utterly Certified
Posts: 22,726
From: Melton Mowbray,Leicestershire (U.K)



Hi
I'm not what process code your using to email the report but with regard to the end of the month check.
You can evaluate the current date against the end date of the current month.
CODE
If Date = DateSerial(YEAR(Date), Month(Date) + 1, 0) Then
DoCmd.SendObject _
    , _
    , _
    , _
    "larry.larsen@ntlworld.com", _
    , _
    , _
    "Subject", _
    "Message", _
    True
Else
MsgBox "Not Now.."
End If

(IMG:http://www.utteraccess.com/forum/style_emoticons/default/thumbup.gif)
Go to the top of the page
 
+
lillyellen
post Mar 8 2007, 07:17 AM
Post #3

UtterAccess Addict
Posts: 132



Thanks for replying so quickly,

I currently e-mail reports on specific days in the week using the On Load event, but didn't know the code for the month end, with different dates etc.

Your code works perfectly, but my manager has asked if the report could be sent at the end of the day, i.e. 4.00pm to take into account sales on that last day.

Do you know how I can set this up?

I appreciate all your help very much.

Regards

Martin
Go to the top of the page
 
+
freakazeud
post Mar 8 2007, 07:31 AM
Post #4

UtterAccess VIP
Posts: 31,413
From: NC, USA



Hi,
just include that in your condition e.g.:

If Date() = DateSerial(YEAR(Date), Month(Date) + 1, 0) AND Time() > #04:00:00 PM# Then
...

However, this does NOT guarantee that the report will be send. What happens if no one opens the file after 4 anymore? You might want to consider using a macro to execute your email function and automate the calling of this macro with a batch file and the macro command line switch. You can then schedule the batch file with the windows scheduler or some other scheduling software. This would take the human aspect out of the process.
HTH
Good luck
Go to the top of the page
 
+
lillyellen
post Mar 8 2007, 07:44 AM
Post #5

UtterAccess Addict
Posts: 132



Thanks very much,

You're right, the file will be opened in the morning, and left open all day. I hoped that the On Timer event might trigger the e-mail at 4.00 pm.

I am self taught with access, and setting up macros is something I know nothing about. Would I enter the same code for the On Load event when I create the macro?

Please help.

Thanks very much,


Martin.
Go to the top of the page
 
+
freakazeud
post Mar 8 2007, 07:52 AM
Post #6

UtterAccess VIP
Posts: 31,413
From: NC, USA



Hi,
the on timer event would work if you can guarantee that the application will be open 24/7.
There is nothing fancy about the macro approach.
Take your email code (everything without the evaluation part since you won't need it when utilizing the scheduler).
Paste it into a new public function in a new module e.g.:

Public Function ScheculedEmail()

'your email code

End Function

Then close and save the module as something different then the function within it.
Create a new macro...in the action argument pick RunCode...in the Function Name property write the name of your function you just created e.g. ScheculedEmail(). When automating this with the scheduler you should add another action to the macro or the function itself which shuts down the application after it is done with its process to make sure it doesn't stay open.
Now you can create a new batch file and call your created macro with the macro command line switch e.g.:

C:
CD\Program Files\Microsoft Office\Office
Msaccess.exe C:\Northwind.mdb /x YourMacroName

Then schedule the batch file. You can read a little more detail about this process here.
HTH
Good luck
Go to the top of the page
 
+
lillyellen
post Mar 8 2007, 08:25 AM
Post #7

UtterAccess Addict
Posts: 132



Brilliant,

This is a great help, thanks very much for your advice, it is very much appreciated.

All the best


Martin
Go to the top of the page
 
+
freakazeud
post Mar 8 2007, 08:31 AM
Post #8

UtterAccess VIP
Posts: 31,413
From: NC, USA



You're welcome.
Good luck on future projects!
Go to the top of the page
 
+

Thank you for your support! Reply to this topicStart new topic

Jump To Forum:
 



RSS Go to Top  ·  Lo-Fi Version Time is now: 19th June 2013 - 03:53 AM