Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Procedure based on date

Posted on 2003-03-06
5
Medium Priority
?
179 Views
Last Modified: 2010-05-01
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.
0
Comment
Question by:otay_buwheat
  • 3
5 Comments
 
LVL 3

Expert Comment

by:happel
ID: 8083822
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
 
LVL 11

Accepted Solution

by:
supunr earned 300 total points
ID: 8084132
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
 
LVL 11

Expert Comment

by:supunr
ID: 8084137
Note: only the Form_Load funcction has been changed....
0
 
LVL 11

Expert Comment

by:supunr
ID: 8084148
actually declare LastYearMonth within Form_Load

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

Good Luck!
0
 

Author Comment

by:otay_buwheat
ID: 8088358
That worked perfectly.  Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question