Convert Short time to decimals

C

Chad

Hello, I have a form named frmDecimalConversion. And on this form I have two
text boxes (txtMinutes and txtDecimal) the txtMinutes you enter your minutes
into and the txtDecimal wil convert to decimals. Example:

480 minutes (typed into txtMinutes) will give you a result of 8 in the
txtDecimal box

Here is the code in the After Update in the txtMinutes box.

Private Sub txtMinutes_AfterUpdate()
Me.txtDecimal = Round(Me.txtMinutes / 60, 2)
End Sub

Everything works great except I want to change from minutes to short time
(Example)

4:45 typed into txtMinutes box will result in 4.75 in the txtDecimals box.

Can someone help me on the VBA code for the formula? instead of the
Me.txtDecimal = Round(Me.txtMinutes / 60, 2)

Thanks!!
 
M

missinglinq via AccessMonster.com

There may be an easier way, but this does it:

Me.txtDecimal = Format(Me.TxtMinutes, "h") & Format((Minute(Me.TxtMinutes) /
60), ".##")
 
M

missinglinq via AccessMonster.com

I wish someone could explain to me why, with all the space left in the margin,
this forum split that line of code! Make sure that the code I gave you is all
 
D

Douglas J. Steele

You have to remember that, regardless of how you're posting to this
newsgroup, it's an NNTP newsgroup under the covers.

Traditionally, line lengths in NNTP are limited to 76 characters.
 
M

missinglinq via AccessMonster.com

Thanks for the explanation, Doug!
You have to remember that, regardless of how you're posting to this
newsgroup, it's an NNTP newsgroup under the covers.

Traditionally, line lengths in NNTP are limited to 76 characters.
I wish someone could explain to me why, with all the space left in the
margin,
[quoted text clipped - 7 lines]
 
J

John W. Vinson

Everything works great except I want to change from minutes to short time
(Example)

4:45 typed into txtMinutes box will result in 4.75 in the txtDecimals box.

Can someone help me on the VBA code for the formula? instead of the
Me.txtDecimal = Round(Me.txtMinutes / 60, 2)

Try:

Round(DateDiff("n", #00:00:00#, CDate(Me.txtMinutes)) / 60, 2)


John W. Vinson [MVP]
 

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