VB and VBA Users Source Code: Preventing a DTPicker (date picker) control from changing
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Preventing a DTPicker (date picker) control from changing
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Tuesday, September 10, 2002
Hits:
1184
Category:
Windows API
Article:
The default behaviour of the DTPicker control is to change the date when scrolling through the dates with the calendar. The following code ensures that the date only changes when you select a new date. This is particulary useful when using two controls to specific date ranges. Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private zdtCurrentDate As Date, zdtNewValue As Date 'Purpose : Test to see if a DTPicker's calendar is visible 'Inputs : N/A 'Outputs : Returns True if a DTPicker's calendar is visible 'Author : Andrew Baker 'Date : 11/Sep/2002 13:17 'Notes : You will need to a the MSCOMCT2.OCX component to your project 'Revisions : 'Assumptions : Function DatePickerAreaVisible() As Boolean If FindWindow("msvb_lib_monthview", "") Then DatePickerAreaVisible = True Else DatePickerAreaVisible = False End If End Function 'This demonstration prevents the date changing while the date calendar is visible Private Sub DTPicker1_Change() Static sbNoRecursion As Boolean If DatePickerAreaVisible Then 'The date picker drop down is displayed sbNoRecursion = True 'Store the selected date zdtNewValue = DTPicker1.Value 'Reset the date back to the current value DTPicker1.Value = zdtCurrentDate sbNoRecursion = False End If End Sub Private Sub DTPicker1_CloseUp() DTPicker1.Value = zdtNewValue End Sub Private Sub DTPicker1_DropDown() 'Store the current date when the calendar is shown zdtCurrentDate = DTPicker1.Value End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder