Solved

Execute code on specific day

Posted on 2013-06-18
4
252 Views
Last Modified: 2013-06-19
The code below executes the 9th of each month.  I would like to change the following vb6 code to execute when it is only July 9,2013.

currentservertime already contains the current date.  

How do I do that?

If Day(currentServerTime) < 9 Then
                    'Add code here
            End If

Open in new window

0
Comment
Question by:al4629740
  • 2
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
Faustulus earned 500 total points
ID: 39258237
How about this?
If Date = DateSerial(2013,7,9) Then
    ' add your code here
End If

Open in new window

You can expand on the idea like this:-
If Now > (DateSerial(2013,7,9) + TimeSerial(12,0,0)) Then
    ' add your code here
End If

Open in new window

This would run any time after 12 pm on July 9. Your code could include a line to abort if the time window you want to allow is exceeded.
Basically, if you wish a program to run on July 9, 2013 you would need to set a timer which would wake up the computer and run the program when the time has arrived. This is what they use for automatic backups. The above kind of code would need to be called by the user or, perhaps a startup procedure, and then refuse to run at any other time. But it could be run multiple times within the prescribed time frame unless your code includes provision to allow it to run only once.
0
 

Author Comment

by:al4629740
ID: 39258379
Can I do
July 9, 2013. 8:00pm
0
 

Author Comment

by:al4629740
ID: 39258430
This didn't work.  Do I have the format wrong

If Date = DateSerial(2013,7,9) Then
    ' add your code here
End If
0
 
LVL 14

Expert Comment

by:Faustulus
ID: 39258554
TimeSerial(20,0,0) would define 8 pm. The parameters are Hour, Minute, Second - all counting from 00:00 h military time.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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 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…
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now