DTPicker Control (VBCCRDTPicker)
The VBCCRDTPicker control is a date-time picker that provides a dropdown calendar interface, allowing users to easily select dates and times.
Properties
DateTime Properties
Value: Currently selected date and timeYear: Current yearMonth: Current monthDay: Current dayHour: Current hourMinute: Current minuteSecond: Current secondMinDate: Minimum selectable dateMaxDate: Maximum selectable date
Display Properties
Format: Display formatdtpShortDate: Short date formatdtpLongDate: Long date formatdtpTime: Time formatdtpCustom: Custom format
CustomFormat: Custom format stringUpDown: Whether to display up/down adjustment buttonsRightToLeft: Whether to display right-to-leftCalendarBackColor: Calendar background colorCalendarForeColor: Calendar foreground colorCalendarTitleBackColor: Calendar title background colorCalendarTitleForeColor: Calendar title foreground colorCalendarTrailingForeColor: Non-current month date foreground colorCheckBox: Whether to display checkboxChecked: Checkbox state
Events
Change: Triggered when value changesCloseUp: Triggered when dropdown calendar closesDropDown: Triggered when dropdown calendar displaysFormat: Triggered when formatting display valueKeyDown: Key press event
Code Examples
Basic Usage
vb
Private Sub InitDTPicker()
With DTPicker1
' Set date range
.MinDate = DateSerial(2000, 1, 1)
.MaxDate = DateSerial(2030, 12, 31)
' Set current value
.Value = Now
' Set display format
.Format = dtpShortDate
End With
End SubCustom Format
vb
Private Sub SetCustomFormat()
With DTPicker1
.Format = dtpCustom
' Format guide:
' yyyy: 4-digit year
' yy: 2-digit year
' MMMM: Full month name
' MMM: Abbreviated month name
' MM: 2-digit month
' dd: 2-digit day
' ddd: Abbreviated weekday
' dddd: Full weekday name
' HH: 24-hour format
' hh: 12-hour format
' mm: minutes
' ss: seconds
' tt: AM/PM
.CustomFormat = "yyyy-MM-dd dddd"
End With
End SubDate Validation
vb
Private Sub ValidateDate(ByVal NewDate As Date)
With DTPicker1
If NewDate < .MinDate Or NewDate > .MaxDate Then
MsgBox "Please select a date between " & Format$(.MinDate, "yyyy-mm-dd") & _
" and " & Format$(.MaxDate, "yyyy-mm-dd")
' Restore to valid value
If NewDate < .MinDate Then