PDA

View Full Version : Read date and time from active cell to a date picker



AleemAM123
04-03-2011, 08:51 AM
I am trying to read the date and time from and active cell into a date and time picker control:


Private Sub UserForm_Initialize()
' Check if active cell contains a date. If 'yes' show
' same date on calendar. If 'no' show today's date.
If IsDate(ActiveCell.Value) Then
DTPicker1.Value = DateValue(ActiveCell.Value)
Else
DTPicker1.Value = Date
End If
End Sub



This code picks up the date only and leaves the time out, any idea how I can get the time in?

Bob Phillips
04-03-2011, 12:51 PM
Haven't we been here before?

AleemAM123
04-03-2011, 04:36 PM
umm...well I was able to ditch the calendar and use a date and time picker. The calendar can get the date from the cell but with a date and time in, the date picker can get the date but not the time. It is related to the other post. This is not an issue of writing the date and time from a control, it is now getting the control that pops up on a cell to have the value in the cell if it is a date and time.

Bob Phillips
04-04-2011, 02:15 AM
I see. It seems you have to set the Format property of the control to 3 - dtpCustom, and set the CustomFormat property to something like dd MMM yyyy hh:mm:ss (note the capitals for month)