VB and VBA Users Source Code: Entering blank dates in a Date Picker control
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Entering blank dates in a Date Picker control
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Monday, October 01, 2001
Hits:
1162
Category:
Windows Forms/GUI/Controls/Graphics
Article:
Unfortunately, the VB Date Picker control doesn't allow you to enter null dates. To overcome this limitation try using the following work around: You will need a form with a Date Picker control on it called DTPicker1 and a CommandButton called cmdOK. Note, you must add the "Microsoft Windows Common Controls 2-6.0" (MSCOMCT2.OCX) component to your project to use the Date Picker. Option Explicit Private Sub cmdOK_Click() Dim sMyDate As String If Me.DTPicker1.Format = dtpShortDate Then sMyDate = Me.DTPicker1.Value Else sMyDate = "null" MsgBox "You have not selected a date..." End If End Sub Private Sub DTPicker1_CloseUp() Me.DTPicker1.Format = dtpShortDate End Sub Private Sub DTPicker1_KeyUp(KeyCode As Integer, Shift As Integer) If DTPicker1.Visible Then If KeyCode = vbKeyDelete Then DTPicker1.Format = dtpCustom DTPicker1.CustomFormat = " " Else DTPicker1.Format = dtpShortDate End If End If End Sub Private Sub Form_Load() Me.DTPicker1.Format = dtpCustom Me.DTPicker1.CustomFormat = " " End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder