Solved

Calculation Question

Posted on 2002-06-26
3
143 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

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 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…

806 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