Form-Timer; run multiple macros.

  • Thread starter a0a349 via AccessMonster.com
  • Start date
A

a0a349 via AccessMonster.com

I am attempting to use the below code for a scheduled db; depending on the
date/day, it is supposed to run the corresponding macro.
Now, the 1st one (weekly) is working/running.
But I set up a second scheduled task to handle the monthly macros, and
nothing happens.

Private Sub Form_Timer()

If Weekday(Date) = 2 Then
DoCmd.RunMacro "mcrRun_Data-Weekly"
If Weekday(Date) = 4 Then
DoCmd.RunMacro "mcrRun_Data-Monthly"
If Month(Date) = 3 Then
DoCmd.RunMacro "mcrRun_Data-Monthly2"
If Month(Date) = 9 Then
DoCmd.RunMacro "mcrRun_Data-Monthly1"
End If
End If
End If
DoCmd.Quit
End If
End Sub


Any thoughts?

Thanks!
Jen
 
J

John W. Vinson

I am attempting to use the below code for a scheduled db; depending on the
date/day, it is supposed to run the corresponding macro.
Now, the 1st one (weekly) is working/running.
But I set up a second scheduled task to handle the monthly macros, and
nothing happens.

Private Sub Form_Timer()

If Weekday(Date) = 2 Then
DoCmd.RunMacro "mcrRun_Data-Weekly"
If Weekday(Date) = 4 Then
DoCmd.RunMacro "mcrRun_Data-Monthly"
If Month(Date) = 3 Then
DoCmd.RunMacro "mcrRun_Data-Monthly2"
If Month(Date) = 9 Then
DoCmd.RunMacro "mcrRun_Data-Monthly1"
End If
End If
End If
DoCmd.Quit
End If
End Sub


Any thoughts?

The code between an If...Then line and the corresponding End If line is
executed only if the IF is true.

Your lines checking for Weekday = 4, 3, etc. *never get executed at all*
unless it's Monday, because they're inside the IF block!

Try using the ElseIf construction:

If Weekday(Date) = 2 Then
DoCmd.RunMacro "mcrRun_Data-Weekly"
ElseIf Weekday(Date) = 4 Then
DoCmd.RunMacro "mcrRun_Data-Monthly"
' note that this will run every Wednesday, not monthly
End If

Perhaps you could explain the logic in words. You're mixing days of the week
and months of the year in a way that I just don't understand.
 

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