Adding a time in a textbox field (1 Viewer)

ivonsurf123

Registered User.
Local time
Today, 07:15
Joined
Dec 8, 2017
Messages
69
Hello,

Private Sub TimeSpentFI1_Click()
Dim number As Integer
Me.TimeSpentFI1.Text = Format(number, "0.00")
End Sub

I need help on this one, I need to be able to insert a number 1 or 30 and the textfield recognize it as time like 1 - 1hr spent or 30 = 30 minutes spent, any help will be appreciate it, I tried but all that I could get was Decimals entering. Thank you.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:15
Joined
Feb 19, 2013
Messages
16,630
the .text property is only valid if the control has the focus. you do not need .text

date and time is stored as a decimal number, the bit before the dp is the date as a number calculated from when 31/12/1899=1, today is 43138.

The bit after the dp is the time expressed as number of seconds divided by the number of seconds in 24 hours (86400) so now (16:24) is .6837847222

So 30 minutes in time type is 30*60/86400=0.02

So having now had an explanation of how time works as a datatype, you need to explain more about what you are trying to do.

Is your control TimeSpentFI1 bound a to field in a table?

What is the click supposed to do?

How is any calculation supposed to know that 1 means 1 hour and not 1 minute? or are you saying the only possible entries a user can make is 1 or 30

Note that time can only be formatted as time providing the time element value is less than 1, you cannot format time for greater than 24 hours - adding 10 hours to 15 hours will not show 25 hours, it will show 1 hour.

Having got the data what do you do with it? add it to a start time? deduct from an end time? something else?
 

ivonsurf123

Registered User.
Local time
Today, 07:15
Joined
Dec 8, 2017
Messages
69
Thank you for your reply, the data collect it from that textfield is bound to a table, I should use before or after update instead of click, my bad, by hour or by minutes if I enter 1, good questions, do not have the answer to that, maybe just enter decimals values like 1 hour would be interpreter as 1:00 or 30 minutes as 0:30, but still do not have the answer on how to do it that way if possible.
 

CJ_London

Super Moderator
Staff member
Local time
Today, 15:15
Joined
Feb 19, 2013
Messages
16,630
if it is bound to a field in a table - what is the field type? date? numeric? - and if the latter what type? long/integer/double?

why can't the user just enter the number of minutes? i.e. 60 for one hour?

you have not answered all my questions so I can only speculate what the answer might be.

Best I can suggest is that the bound field should be a date datatype and you format it as "hh:nn"
 

ivonsurf123

Registered User.
Local time
Today, 07:15
Joined
Dec 8, 2017
Messages
69
Thank you,

Field Type = Numeric Long Integer

I did not think about it 60 minutes = 1 hour

I was thinking more to enter as decimal 1 hour means = 1.0 or 30 minutes = .30

I will try what you have suggested.

Cheers!
 

Users who are viewing this thread

Top Bottom