Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stop a program after a certain date

Status
Not open for further replies.

tenbellies

Programmer
Dec 20, 2002
17
GB
I need to put some added security on a program i'm trying to add some code like this

sub form_load
if Date <= 01/01/2004 then
msgbox &quot;Date Error&quot;
unload me
Exit sub
end if

End sub

This won't work have tried other ways of coding but can't get it to work any one help.....
 
Try this:
Private Sub Form_Load()
If Date <= &quot;1/6/2004&quot; Then
MsgBox &quot;Date Error&quot;
Unload Me
End If
End Sub

Hope the helps!
 
Be careful (both of you). You are a) actually doing a string comparison due to an implicit cast, b) not considering user date settings

 
Thanks, both of you, the code works i have thought about the date but can't think of a better way
 
strongm, Good point. tenbellies, try this:

Private Sub Form_Load()
If Date <= CDate(&quot;1/7/2004&quot;) Then
MsgBox &quot;Date Error&quot;
Unload Me
End If
End Sub

The cdate function converts the string sent to it to a date format variable consistent with user settings on the computer that the app is being run on. If you haven't seen this, it's worth searching for on help as there are a number of similar functions that are useful to be aware of.

Hope that helps!
 
No, still not good enough...must try harder (I'm just trying to encourage you to think this through a little bit more). Consider this: is the date represented by the string &quot;1/7/2004&quot; 1st July 2004 or 7th January 2004?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top