Printable Version of Topic

Click here to view this topic in its original format

UtterAccess Forums _ Access Date + Time _ Editing Time On Form Issue

Posted by: AP_Ben Mar 25 2020, 01:56 PM

Hi, I thought this should be simple, but am about to assume it can't be done....

I have a form which records time start and time finish with some other data, and defaults to current time for both start and finish when the form opens. There are also a couple of buttons which automatically enter the current time into either the
start or end time fields when required. Elapsed time is calculated when the record is saved This works absolutely fine when I remember to click the buttons, and if I start work when I open the form. However often I pre-open the form and enter some basic details before calling the customer - and then forget to press the current time button when they answer the phone. Or all is good, but I forget to press end time when I'm done, and find the form lying about on the screen a bit later on when I close whatever windows I have been working on.

At times like those, all I want to do is click into the relevant time field, and amend the value. As soon as I click in the field however, the very nice 13:15 display changes in a massive long date with time including seconds field, where I have to fiddle about with the mouse trying to get the cursor into just the right place to be able to edit correctly. No amount of formatting the field definition or the text box format changes this behaviour.

I am beginning to think I will have to resort to either a couple of combo boxes, one for hours, one for minutes in 5-minute intervals, or some sort of double text box with numbers for hours in one, and minutes in the other, which I do some sort of behind the scenes jiggery pokery to turn back into time. Needless to say I don't like either approach.

Can anyone suggest a convenient way of displaying time in hours and minutes (such that I can calculate elapsed time - I'm not worried about passing midnight) where I can easily edit the values?

Many thanks

Posted by: tina t Mar 25 2020, 02:03 PM

QUOTE
Can anyone suggest a convenient way of displaying time in hours and minutes (such that I can calculate elapsed time - I'm not worried about passing midnight) where I can easily edit the values?

try setting the InputMask property of both textbox controls in the form (not at the table level). you can read up on the property in Access Help.

hth
tina

Posted by: Gustav Mar 25 2020, 04:31 PM

My project https://github.com/GustavBrock/VBA.TimeEntry is for you.



Here is the demo:  TimeEntry.zip ( 38.56K ): 5
.

Posted by: Larry Larsen Mar 26 2020, 07:36 AM

Hi
Would also like to throw into the mix, some thing I found here on UA many years ago.

Note: Note my work so I'm not claiming any kudos, but did like both the visual and process aspect of the time logger..

All I have added is the time difference calculations, and hopefully show you alternative option..

Have also added Gustav demo/example to my growing library..

(Hi Gustav really great to see you back here at UA..)

Have attached an image to show you.. (WIP)

HTH's
thumbup.gif

 

Posted by: AP_Ben Mar 26 2020, 07:57 AM

Tina, I think this works for me (it did on a test form, but I believe the format property might be conflicting on the real system so I'll figure that out shortly) - many thanks
Gustav - fascinating, I don't understand a word of the code, but it works so I shall spend some time figuring it out!
Larry, the form looks good and useful - are you suggesting this is a demo project on here somewhere?

Again, many thanks all

Ben

Posted by: Larry Larsen Mar 26 2020, 08:38 AM

Hi Ben

It was posted as an example many moons ago, I was luck enough to grab it..

The image is what I'm just tiding up and will post it up for you if you like.. (WIP) Work In Progress...

Larry
thumbup.gif

Posted by: AP_Ben Mar 26 2020, 09:10 AM

Thanks Larry, I'm still struggling; using input mask sort of works, but as soon as I press the button which puts in the current time, it doesn't like the format

CODE
Private Sub butTimeNow_Click()
EndTime.SetFocus
EndTime.Text = Format(Now(), "hh:mm")

End Sub

the fields also seem to insist on including seconds, although I can at least now click in them and change the hours or minute figures (and probably the seconds, but never bothered or wanted to do that). for instance thr default value for StartTime when I open the form is the same, Format(Now(), "hh:mm") but the display is 14:05:00
Oddly the seconds figure is always zero....

Ben
edit: noticed in my test form (based on Gustav's app) that although everything is good to start with, if I once press my 'timenow' button, although it looks OK if I then edit the field (e.g. click in it) it has returned to long date format

Posted by: Larry Larsen Mar 26 2020, 09:24 AM

Hi Ben

Not really sure what's happening in that code segment, find attached my (WIP) example and see if you can work it..

If you follow the process of the demo you may be able to use/fit into your application..

Let me know how it goes..Larry

Demo is in A2010 but should scale up OK..

thumbup.gif

 Demo_TimeclockStamp_2020.zip ( 39.96K ): 7
 

Posted by: AP_Ben Mar 26 2020, 09:30 AM

removed the date picker from the time fields, and added a button to put in the current time, and so far seems to work. Shall look at what you have done now and experiment further

Thanks
Ben

Posted by: AP_Ben Mar 26 2020, 09:41 AM

This is bizarre - you (or someone) haven't done anything to those fields at all! Some fancy code to calculate the elapsed time, which is all very good and well documented but login/logoff fields are just vanilla, no input masks and the table definition just specifies short time.

I'll have to recreate my form from scratch and see if I can spot something, as that was how mine was set up before I threw the kitchen sink at trying to get it to behave.
Incidentally, my basic elapsed time calculator seems to work fine (haven't tested it spanning midnight etc, however....)

CODE
Private Sub timeToMins()
Dim timediff
Dim minute As Single
timediff = Format((EndTime - StartTime), "hh:mm")
TotalTime = timediff
minute = DateDiff("s", [StartTime], [EndTime])
totMins = minute / 60
End Sub

Posted by: Gustav Mar 27 2020, 04:06 AM

Unless you have a need for rounding the time values to the second, you can calculate the minutes directly:

CODE
TotalMinutes = (EndTime - StartTime) * 24 * 60


And you should use "nn" for the minutes:

CODE
TimeDiff = Format(EndTime - StartTime, "hh:nn")