Time in a TextBox

  • Thread starter Thread starter Patrick C. Simonds
  • Start date Start date
P

Patrick C. Simonds

I would like the code below to put the current time (in 24 hour format) in
TextBox3. So how can I modify this so I only get the time and not the date
and have the displayed time in the 24 hour format (18:45 for 6:45pm)

Private Sub TextBox1_Change()
TextBox3.Value = Now()
End Sub
 
There is also a Time function in VB, but you would still need to use the
Format function to get 24-hour time (unless your computer's local setting
for time is already formatted as 24-hour time)...

TextBox3.Value = Format$(Time, "hh:mm")

Note that I did not use Time() for the function call as the parentheses on a
function call are not needed when they contain no arguments between them.
So, your Now() function call would also work just as well if you used Now
instead (this is different than function calls in formulas on the worksheet
itself where the parentheses are always needed).
 
Back
Top