Procedure based on date

I am trying to run a procedure based on the first day of each month.  However this procedure doesn't work if the program didn't run on the first day of the month.  How can I get it to check to see if it skipped the first day of the month and run the procedure?

Example:

Private Sub Form_Load()

If DatePart("d", Date) = 1 Then
        Call AddTime
End If
End Sub

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

Private Sub AddTime()
   
    'Add earned vacation time to appropriate month
    'Jan
    If DatePart("m", Date) = 1 Then
        With deTime
        Do Until .rscomTime.EOF
            If DateDiff("yyyy", .rscomTime.Fields("StartDate").Value, Date) < 7 Then
                .rscomTime.Fields("VacDec").Value = .rscomTime.Fields("VacDec").Value + 7.5
            ElseIf DateDiff("yyyy", .rscomTime.Fields("StartDate").Value, Date) < 15 Then
                .rscomTime.Fields("VacDec").Value = .rscomTime.Fields("VacDec").Value + 9.375
            ElseIf DateDiff("yyyy", .rscomTime.Fields("StartDate").Value, Date) >= 15 Then
                .rscomTime.Fields("VacDec").Value = .rscomTime.Fields("VacDec").Value + 13.125
            End If
            .rscomTime.MoveNext
        Loop
        .rscomTime.MoveFirst
        End With
    End If
End Sub

I would like something that will check to see if the first day of the month was skipped and move to the next day and so on until the procedure has run once.  However, my admitted limit of VB knowledge is preventing me from accomplishing this goal.  Any help is very much appreciated.
otay_buwheatAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

happelCommented:
You can use the VB function 'Day' to get the daynumber.
Like:
intDayOfMonth = Day('21/02/2003')
intDayOfMonth = 21

A procedure to test if day 1 is passed should also know it it already is run, right?

If i'm correct then it would be something like (principle)


Private Sub Form_Load

   'If current month other than last-AddTime-month run AddTime
   If Month(now)<>CheckLastRun then
      Call AddTime
   Else
      'Already run AddTime this month (day doesn't matter)
      'Do nothing
End Sub

'Check last run
private function CheckLastRun as integer  
   'return last month for wich AddTime has run.

   <database>.<GetFromRunTable>.<LastRunMonthNumber>
   OR
   <Registry>.<GetFromKey>.<LastRunMonthNumber>
end function
0
supunrCommented:
Why don't you use registry to store the last run date and use that to figure out if it is not check then run it....
here is your modified code.

Private LastYearMonth as String

Private Sub Form_Load()
     Dim ThisYearMonth as string

     LastYearMonth = GetSetting(App.Title, "Settings", "LastYearMonth", "198001")
     ThisYearMonth = Format(Date, "YYYYMM")

     If (Val(LastYearMonth) < Val(ThisYearMonth)) then
          Call AddTime
          SaveSetting App.Title, "Settings", "LastYearMonth", ThisYearMonth
     End If
End Sub

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

Private Sub AddTime()
   
   'Add earned vacation time to appropriate month
   'Jan
   If DatePart("m", Date) = 1 Then
       With deTime
       Do Until .rscomTime.EOF
           If DateDiff("yyyy", .rscomTime.Fields("StartDate").Value, Date) < 7 Then
               .rscomTime.Fields("VacDec").Value = .rscomTime.Fields("VacDec").Value + 7.5
           ElseIf DateDiff("yyyy", .rscomTime.Fields("StartDate").Value, Date) < 15 Then
               .rscomTime.Fields("VacDec").Value = .rscomTime.Fields("VacDec").Value + 9.375
           ElseIf DateDiff("yyyy", .rscomTime.Fields("StartDate").Value, Date) >= 15 Then
               .rscomTime.Fields("VacDec").Value = .rscomTime.Fields("VacDec").Value + 13.125
           End If
           .rscomTime.MoveNext
       Loop
       .rscomTime.MoveFirst
       End With
   End If
End Sub



Good Luck!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
supunrCommented:
Note: only the Form_Load funcction has been changed....
0
supunrCommented:
actually declare LastYearMonth within Form_Load

Private Sub Form_Load()
    Dim LastYearMonth as String
    ....

Good Luck!
0
otay_buwheatAuthor Commented:
That worked perfectly.  Thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.