Code for first of the month

G

Guest

I want create code that will call a function on the first day of each month.
Any help?
 
G

Guest

Hi,
you could try:

If DateSerial(Year(Date),Month(Date),1) = Date Then
'execute your code
End If

HTH
Good luck
 
D

Dirk Goldgar

freakazeud said:
Hi,
you could try:

If DateSerial(Year(Date),Month(Date),1) = Date Then
'execute your code
End If

Wouldn't

If Day(Date) = 1 Then
' ...

be simpler?
 
P

Peter R. Fletcher

I want create code that will call a function on the first day of each month.
Any help?

Dirk's solution is simplest as long as you can guarantee that the
_calling_ code will run (at least once) on the first day (which may
not be a working day) of every month. If what you really want is to
ensure that your function is called on the first occasion on which the
application and/or calling code runs in each new month, which is
rather different (and somewhat more probable in most business
applications), you will have to be more creative. In this case, you
will need to save the current month value, either in a Table, or in
the Registry, each time the program runs, and compare the new current
month with the saved value on startup to determine if you are in a new
month.

Please respond to the Newsgroup, so that others may benefit from the exchange.
Peter R. Fletcher
 

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