Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Calculation Question

Posted on 2002-06-26
3
Medium Priority
?
149 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
[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 Comments
 
LVL 4

Accepted Solution

by:
gencross earned 800 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

636 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