You need these objects to achieve this:
-- A control table, in which (apart from anything else you might want to hold) you have a
LastUpdateMonth field.
-- An autoexec process which runs every time the database is opened by a user with data update rights
-- VBA code to store the current month number in the control table
-- VBA code to compare the current month number, with the number stored in the control table.
Here is some example code which may help:
1. Update the control table with the current month number
Code:
sub SetLastUpdateMonth
dim strSQL as string
dim strThisMonth as string
strThisMonth = format$(date(),"mm")
strSQL = "INSERT INTO tblControl (LastUpdateMonth) "
strSQL = strSQL & "VALUES ('" & strThisMonth & "')"
DoCmd.SetWarnings (False)
DoCmd.RunSQL (strSQL)
DoCmd.SetWarnings (True)
End Sub
2. Get the stored month number from the table and compare with the current month:
Code:
Public Function CheckMonth()
dim strThisMonth as string
dim strStoredMonth as string
strThisMonth = format$(date(),"mm")
strStoredMonth = DLookup"[LastUpdateMonth]", "tblControl")
if strStoredMonth <> strThisMonth then
Docmd.RunQuery qryYourUpdateQuery
SetLastUpdateMonth
end if
end function
To set up an Autoexec macro:
-- Open the main database window
-- Click on [Macros]
-- Click the [New] button
-- In the 'Action' column, choose 'RunCode'
-- In the 'Function Name' field which appears in the lower half of the window, choose or type the name of the visual basic function, e.g. CheckMonth()
Close the Macros window and save changes.
The process will 'remember' to run your update query, even if the database is not opened until a few days into the next month. I think it would also be sensible to log the fact that the query has run, so you can check that it is working OK.
I hope that these ideas are helpful.
Bob Stubbs