textbox show correct time in userform

T

Titus

Hi,

I'm having problems with a textbox that I created in my userform. The
problem is I have the textbox set to display time ("hh:mm") in the 24
hour mode. Each time the user enters the correct time the textbox will
take the time, but when it re-opens it displays the time as numbers not
time. Once I click in and out of the textbox it reverts to the correct
time. I want the textbox to display the entered time when the userform
is opened.

How can I force my textbox to display time? My VBA code is as follows:
Private Sub TimeTextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TimeTextBox1.Value = Format(TimeTextBox1.Value, "hh:mm")
End Sub

Thanks for your assistance in advance,
Titus
 
F

FM

I'm having problems with a textbox that I created in my userform. The
problem is I have the textbox set to display time ("hh:mm") in the 24
hour mode. Each time the user enters the correct time the textbox will
take the time, but when it re-opens it displays the time as numbers not
time. Once I click in and out of the textbox it reverts to the correct
time. I want the textbox to display the entered time when the userform
is opened.

How can I force my textbox to display time? My VBA code is as follows:
Private Sub TimeTextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TimeTextBox1.Value = Format(TimeTextBox1.Value, "hh:mm")
End Sub

Put your code inside the following sub too:

Private Sub UserForm_Activate()
TimeTextBox1.Value = Format(TimeTextBox1.Value, "hh:mm")
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top