Results 1 to 10 of 10
  1. #1
    GonzaloYagueSunol is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Sep 2015
    Posts
    6

    Run a Macro every 5 minutes automatically

    Dear all,



    I am using access 2013, I have an update query called "CurrentDate" and it is run by a macro called "TimetoTime". I want to run this macro automatically every 5 minutes. After researching different forums and tutorials, I have created a form with the following code:

    ------------------------------------------------------
    Private Sub Form_Open(Cancel As Integer)
    Me.TimerInterval = 300000
    End Sub


    Private Sub Form_Timer()
    DoCmd.RunMacro "TimetoTime"
    End Sub

    ------------------------------------------------

    Unfortunately it does not work. I would really appreciate if anyone could help me solve this problem.

    Thank you very much in advance.

    Best regards,

    Gonzalo

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Has code been enabled for the db or is it in a trusted location?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    GonzaloYagueSunol is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Sep 2015
    Posts
    6
    It has been enabled for the db. There is not any trusted location

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Have you tried setting the timer interval in design view and not using the code to set it? Are you sure the process isn't running, rather than the query not updating anything? Can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    GonzaloYagueSunol is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Sep 2015
    Posts
    6
    Good Morning Paul,

    I do apologize for replying you late.

    As you may see, the CurrentDate query should update every five minutes the "Day Difference","ID Expiry Date" and "Permission" fields through the "TimetoTime" macro. I have tried to run this query manually and it works well.

    Thank you very much again for your time and help.

    Best regards,

    Gonzalo
    Attached Files Attached Files

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    I get errors (no Form2, may be corrupted), but what good would it do to run the query every 5 minutes? Since it uses date, it would only change anything after midnight. Did you mean to use Now() and have times?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    GonzaloYagueSunol is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Sep 2015
    Posts
    6
    Hi Paul,

    With the help of the query (run by the "TimetoTime" macro) I want to achieve this:

    - The "CurrentDate" must be updated with the current date and I do not need the time. That's why I use Date() function.
    - "Day Difference" is calculated as [ID Expiry Date]-[Current Date]
    - "Permission" field is Green, Amber or Red based on the following pattern:

    if [Day Difference]<0, [Permission]=Red
    if 0<=[Day Difference]<15, [Permission]= Amber
    if [Day Difference]>=15, [Permission]=Green

    In order to calculate [Permission] and [Day Difference] as calculated fields, I would need to work with a .accdb file but I cannot do it because of the requirements of the project. For that reason, I work with a .mdb file. Although most of the times [Current Date] will not change (only at midnight), [Day Difference] and [Permission] fields of a potential future new record will be calculated automatically in a short period of time (in this case 5 minutes but it could be even less) without closing and opening the database.

    Thank you very much again for your help and time.

    Best regards,

    Gonzalo

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    Like I said, I got errors but I was able to get rid of all code, set the interval in design view and call the macro in the event property directly and the macro ran on schedule.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    GonzaloYagueSunol is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Sep 2015
    Posts
    6
    Good morning Paul.

    Thanks to this article, I have solved my problem.

    http://www.justanswer.com/microsoft-...query-run.html

    Thank you very much for your time and your help.

    Best regards,

    Gonzalo

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,642
    No problem, I'm glad you got it sorted.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 4
    Last Post: 06-12-2013, 10:20 AM
  2. Automatically run macro overnight
    By kdbailey in forum Access
    Replies: 4
    Last Post: 03-21-2013, 07:11 AM
  3. Replies: 2
    Last Post: 05-26-2012, 01:08 PM
  4. Replies: 1
    Last Post: 05-07-2012, 08:21 AM
  5. Replies: 3
    Last Post: 04-22-2010, 08:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums