Friends again problem with date function
In my form there is a text field -txtDod- of Date type formated like "dd-MMM-yyyy"
My input is also formated like "dd-MMM-yyyy"
Now see my code

 Private Sub TxtDod_KeyPress(KeyAscii As Integer)
 Select Case KeyAscii
 Case vbKeyReturn
 If Not IsDate(TxtDod) Then
 LblMsg = "Enter Date Of Deposit"
 ElseIf (Format$(TxtDod.Text, "dd-MMM-yyyy")) > (Format$(Date, "dd-MMM-yyyy")) Then
 LblMsg = "Date Of Deposit Must Be <= Today"
 End If
 End Select
 End Sub

My problem is I want this-If the input date of TxtDod is greater than Current Date(Today's Date)
the focus should not be shifted to the next text box (txtPrd)
When I tried with the following dates I got the results as follows
14-Feb-2014(Today's Date)Focus shifted to next textbox TxtPrd-Correct
14-Feb-2015 (Date is greater than today) Focus didnot shifted to next field - Correct
13-Feb-2015 (Date is greater) Focus shifted to next field even after the date is greater --Wrong result
14-Feb-2012 (Date is smaller) Focus shifted --Correct
14-Jun-2012 (Date is Smaller) Focus is not shifted even though the date is smaller than today --wrong result
Why this discreepancy? Anything wrong in my code? I am just studying VB6
kindly help me..

Recommended Answers

All 3 Replies

OK That works...But what is wrong with my code? Any mistake..?
Just for academic interest...

There are a few pitfalls working with dates as it always depends on how the compiler works these and can make decisions on what it thinks you want. ALso if you want to compare just numbers you will see that four comes before one because f goes when sorting before o. So generally speaking google as much as you can digest about some of th code if something goe wrong. Please mark this thread as solved.Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.