?
Solved

Procedure based on date

Posted on 2003-03-06
5
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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
Course of the Month8 days, 22 hours left to enroll

764 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