Time field on a Userform?

mattaustin01

Board Regular
Joined
Feb 17, 2009
Messages
184
I realise there's probably an obvious answer to this but I've googled and am unable to find anything useful :eek:

All I need to know is whether there is an easy way to add a field to a userform where a user can enter the time. The best I found so far was in the list of additional controls, but it's essentially a drop down box with every minute of every day in it - is there a better control, and if not is there a way to put an input mask on a standard textbox to force the entry to be hh:mm?

Thanks in advance
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try:

Code:
Private Sub TextBox1_Change()
    Dim Char As String
    Char = Right(TextBox1.Text, 1)
    Select Case Len(TextBox1.Text)
    Case 1 To 2, 4 To 5
        If Char Like "#" Then
            If Len(TextBox1) = 1 Then
                If Val(Char) <= 2 Then Exit Sub
            ElseIf Len(TextBox1) = 2 Then
                If Val(Left(TextBox1.Text, 1) & Char) <= 24 Then Exit Sub
            ElseIf Len(TextBox1) = 4 Then
                If Val(Char) <= 5 Then Exit Sub
            Else
                Exit Sub
            End If
        End If
    Case 3
        If Char Like ":" Then Exit Sub
    End Select
    Beep
    On Error Resume Next
    TextBox1.Text = Left(TextBox1.Text, Len(TextBox1.Text) - 1)
    TextBox1.SelStart = Len(TextBox1.Text)
End Sub
 
Upvote 0
Hi Andrew,

That works great - although I guess it proves that there's no easy way to add a time chooser to a userform!

Many thanks,
 
Upvote 0
I realise there's probably an obvious answer to this but I've googled and am unable to find anything useful :eek:

All I need to know is whether there is an easy way to add a field to a userform where a user can enter the time. The best I found so far was in the list of additional controls, but it's essentially a drop down box with every minute of every day in it - is there a better control, and if not is there a way to put an input mask on a standard textbox to force the entry to be hh:mm?

Thanks in advance

Which control was that?

A Microsoft Date and Time Picker control with the format set to either dtpTime or dtpCustom seems to be what you're looking for?
 
Upvote 0
Hi Colin,

The MS one does sound like what I need but I don't seem to have it - the only controls I can see in the entire list that are time related are LANDesk Time and LANDeskStatic Time, neither of which are much good!

Where can I get the MS time from?
 
Upvote 0
Hi,

If you don't already have it and you're going to be distributing your project around the office (they probably don't have it either) then using it may create more trouble than it's worth, but it can be downloaded from here:

http://support.microsoft.com/kb/297381

You'll then need to register it using the regsvr32 command.




Also see related discussions here:
http://www.mrexcel.com/forum/showpost.php?p=810136&postcount=8
http://www.mrexcel.com/forum/showthread.php?p=1751238


Hope that helps...
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,576
Members
448,972
Latest member
Shantanu2024

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