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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Validation of date field

Status
Not open for further replies.

rundmc

Programmer
Jan 16, 2003
15
US
I want to validate a date field on a VB form and would like to use a date picker if it exists in VB, otherwise I need another way to overcome this validation

Ideas, Please....?
 
You can use the DTPicker control found in Microsoft Windows common controls 2, You will need to add this to your project components. Thanks and Good Luck!

zemp
 
Hi rundmc,
you can use this API. Write this code in your module.

Public Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Public Declare Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long

Public Const DTM_SETRANGE = &H1004&
Public Const GDTR_MIN = 1
Public Const GDTR_MAX = 2



Write this in your Form Load.


'Set MaxDate,MinDate for DTPicker1

Dim TimeArray(1) As SYSTEMTIME
Dim result As Long
DTPicker1.Value = Now
' Define first element of SYSTEMTIME Array to be minimum date.
TimeArray(0).wYear = Int(Format$(Now, "yyyy")) - 99
TimeArray(0).wDay = Int(Format$(Now, "d"))
TimeArray(0).wMonth = Int(Format$(Now, "mm"))



' Define second element of SYSTEMTIME Array to be maximum date.
TimeArray(1).wDay = Int(Format$(Now, "d"))
TimeArray(1).wMonth = Int(Format$(Now, "mm"))
TimeArray(1).wYear = Int(Format$(Now, "yyyy"))

' Call API to send message to control to set MinDate and MaxDate.
result = SendMessage(Me.DTPicker1.hwnd, DTM_SETRANGE, _
GDTR_MIN + GDTR_MAX, TimeArray(0))
 
There is an easier way to set minimum and maximum dates in a DTPicker control:

Dtpicker1.MinDate = "1 Jan 2003" ' set to fixed date
Dtpicker1.MaxDate = Date + 365 ' set to 1 year forward
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top