Solved

Calculation Question

Posted on 2002-06-26
3
142 Views
Last Modified: 2010-05-02
I need to call a SQL SP with this following idea:

Start January 10th
Run once every 2 weeks until January 10th

I don't know how to code VB for this.  I know how to code the following:

 Do While frmmain.Caption = "Employee Time Tracking Tool"
    DoEvents
   If Hour(Now) = 6 And Minute(Now) = 35 Then

    Set qy9ActiveConnection = conn1
    qy9.CommandType = adCmdStoredProc
    qy9.CommandText = "sp"
    qy9.Execute
0
Comment
Question by:baddogi
3 Comments
 
LVL 4

Accepted Solution

by:
gencross earned 200 total points
ID: 7111371
If you want to run something routinely you need to know when the last time it was run was.  Once you have the last time it was run you can establish a time for it to run again.  Example...

Say you store in the database or an INI file the Last run date and time.

Retrieve the date and time and it is 1/10/02 at 6:30 PM

You would want to add two weeks to the date

Dim dtLastRun as Date
Dim dtNextRun as Date

dtLastRun = "1/10/02"

dtNextRun = dtLastRun + 14

if date >= dtNextRun then
    'Check time if you want.  If it is 6:30 or after then run it
end if

Let me know if I am off base here or if you would like more info.

If you would provide more info. on what you are doing someone may be able to share a good solution.
0
 
LVL 18

Expert Comment

by:mdougan
ID: 7111393
If you have a routine that runs at least once each day, then you can do this:

Dim vTestDate as variant
vTestDate = CDate("1/10/2003)"

If DateDiff("d", Date(), vTestDate) Mod 14 = 0 Then

   Set qy9ActiveConnection = conn1
   qy9.CommandType = adCmdStoredProc
   qy9.CommandText = "sp"
   qy9.Execute

End if

What this will do is tell you if the current date is (2 Weeks * n) away from the critical date.
0
 

Author Comment

by:baddogi
ID: 7111452
Thanks to all responders.  I knew it had to be something simply but when you're stressed you can't think clearly.

I think this should work fine.

Thanks,

0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now