Solved

Calculation Question

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

733 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