Consulting

Results 1 to 4 of 4

Thread: Read date and time from active cell to a date picker

  1. #1

    Question Read date and time from active cell to a date picker

    I am trying to read the date and time from and active cell into a date and time picker control:

    [VBA]
    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

    [/VBA]

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

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Haven't we been here before?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    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.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    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)
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •