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" TxtDod.SetFocus ElseIf (Format$(TxtDod.Text, "dd-MMM-yyyy")) > (Format$(Date, "dd-MMM-yyyy")) Then LblMsg = "Date Of Deposit Must Be <= Today" TxtDod.SetFocus Else TxtPrd.SetFocus 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..