DTPicker1 Format

Digitborn.com

Active Member
Joined
Apr 3, 2007
Messages
353
Hello,

How can I retrieve from UserForm DTPicker1 to a Cell only the time value?

I tried:
Code:
Private Sub CommandButton5P1_Click()
Dim MyDate1 As Date
MyDate1 = DTPicker1.Value

DTPicker1.Format = dtpTime

DTPicker1.Value = Format(Time, "Short Time")
'or
DTPicker1.Value = Format(MyDate1, "h:mm")

ws.Cells(lRow, 13).Value = MyDate1
'or
ws.Cells(lRow, 13).Value = DTPicker1.Value
End Sub
I really couldn't make it by myself, trying to read all kind of topics about DTPicker1 Format :(

The result is or:
12:00:00 AM - returns the defaul value in the cell

7/20/2007 11:44 - returns the date + the correct time filled in the UserForm

I'd like to return in the cell only the "h:mm".
Thanks in advance :rolleyes:
 
Well for 2 the format when I use dtpTime is 23:00, AM/PM is not included.

As to 1 I don't think it's actually possible
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
OK, I cut the Width of the DTPicket and AM/PM is not included, but do you know how it shows you 23:00. Everytime I write 23, it automatically changes to 11:00:00 PM.
 
Upvote 0
Instead of using the DTPicker why not just use spin buttons and textboxes?
 
Upvote 0
Because I don't know how to control the textboxes with spin buttons, can you give me an example? I've never used spin buttons before..I don't know how to validate them for 00:00 - 23:00 o'clock too..
 
Upvote 0
What about comboboxes instead then?
 
Upvote 0
I decided, I like DTPicker, but if it's possible for 23:00 time to appear and :00 (seconds) to disappear. If you know how to, that would be great :)
 
Upvote 0
It's alright to like a particular control.

But is it wise to stick with it if it doesn't actually do what you want it to?

By the way if whatever you are doing is being distributed you might run into problems since the control isn't standard.
 
Upvote 0
Use the Custom Format: HH:mm, note; change the Format to 3 or dtpCustom.

Code:
Private Sub UserForm_Initialize()
       With Me.DTPicker1
        .Format = dtpCustom
        .CustomFormat = "HH:mm"
        'display spinbutton
        .UpDown = True
        .Value = Now
    End With
End Sub
 
Upvote 0
I've just noticed that you wanted to display AM/PM, in which case use

Code:
 .CustomFormat = "HH:mm tt"
 
Upvote 0
Roy, thanx, all that works right as I like it :)
One more thing I wonder, is it possible to Align center the value in DTPicker?
 
Upvote 0

Forum statistics

Threads
1,215,198
Messages
6,123,593
Members
449,109
Latest member
Sebas8956

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top