PDA

View Full Version : Time format and difference between 2 times



sharky12345
01-09-2012, 01:53 PM
Guys,

I know how to do this with Excel but for some reason it won't work with Word:

I have 3 Textboxes, I want all of them to be formatted when the user tabs out of the box by putting the time in as 'HH:MM'. I then want Texbox3 to automatically tell me the duration between TextBox1 and Textbox 2.

Can anyone help?

mdmackillop
01-09-2012, 04:30 PM
Try
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox1.Text = Format(Now, "hh:mm:ss")
End Sub

Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
TextBox2.Text = Format(Now, "hh:mm:ss")
TextBox3.Text = Format(TimeValue(TextBox1) - TimeValue(TextBox2), "hh:mm:ss")
End Sub

sharky12345
01-09-2012, 11:36 PM
Thanks for that - I've tried it and it keeps putting the current time in no matter what I type in the box, any ideas?

mdmackillop
01-10-2012, 06:40 AM
I want all of them to be formatted when the user tabs out of the box by putting the time in as 'HH:MM'
There was no mention of typing in the box. Which are you typing into?

sharky12345
01-10-2012, 09:56 AM
TextBox1 and TextBox2, 1 is the start time and 2 is the end time, Textbox3 should give the duration between the 2.

macropod
01-10-2012, 07:36 PM
What kind of textboxes are you working with: userform textboxes, textbox formfields, etc?

sharky12345
01-10-2012, 10:29 PM
Paul,

I'm working with Textboxes on a Userform - I'm not too familiar with the Word side of things but thought that the code I had in Excel would work in Word?

macropod
01-10-2012, 11:47 PM
Unless your textboxes were using some Excel-specific code, they should work just as well in Word too. As yet, though, you haven't posted any code so it's hard for anyone to say what the issue might be.