Results 1 to 3 of 3
  1. #1
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Shetland Isles, Shetland, Scotland
    Posts
    153
    Thanks
    3
    Thanked 1 Time in 1 Post

    Run a macro once a day (2000 SP3)

    Hi,
    I've a series of make table queries that I'd like run once a day.

    The ideal scenario would be that I could list them in an autoexec macro & the first "thing" in the macro would be a check to see if it had already run that day, if it had, it would exit.

    I've searched on "once per day" and "once a day" but couldn't find anything relevant.

    Jim MacLeod
    Shetland Islea

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Run a macro once a day (2000 SP3)

    Create a table tblLastRun with a single field LastRun of type Date/Time.
    Create a single record and enter a date in the past, e.g. 01/01/1999.

    Create a function in a standard module:

    Public Function OnceADay()
    Dim dtmDate As Date
    dtmDate = DLookup("LastRun", "tblLastRun")
    If dtmDate = Date Then
    ' Code has already run today
    Exit Function
    End If
    ' Your code here
    DoCmd.OpenQuery ...
    DoCmd.OpenQuery ...
    ...
    ' Update the LastRun field in the table
    DoCmd.SetWarnings False
    DoCmd.RunSQL "UPDATE tblLastRun SET LastRun = Date()"
    DoCmd.SetWarnings True
    End Function

    Call this function from your AutoExecute macro (using the RunCode action)

  3. #3
    2 Star Lounger
    Join Date
    Feb 2001
    Location
    Shetland Isles, Shetland, Scotland
    Posts
    153
    Thanks
    3
    Thanked 1 Time in 1 Post

    Re: Run a macro once a day (2000 SP3)

    Fantastic, I'll try this right now!

    Cheers Hans,

    Jim

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •