UtterAccess.com
X   Site Message
(Message will auto close in 2 seconds)

Welcome to UtterAccess! Please ( Login   or   Register )

Custom Search
 
   Reply to this topicStart new topic
> Editing Time On Form Issue, Access 2016    
 
   
AP_Ben
post Mar 25 2020, 01:56 PM
Post#1



Posts: 54
Joined: 11-February 20



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
Go to the top of the page
 
tina t
post Mar 25 2020, 02:03 PM
Post#2



Posts: 6,598
Joined: 11-November 10
From: SoCal, USA


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

--------------------
"the wheel never stops turning"
Go to the top of the page
 
Gustav
post Mar 25 2020, 04:31 PM
Post#3


UtterAccess VIP
Posts: 2,244
Joined: 21-February 07
From: Copenhagen


My project VBA.TimeEntry is for you.

Attached File  TimeEntryTitle.png ( 14.61K )Number of downloads: 4


Here is the demo: Attached File  TimeEntry.zip ( 38.56K )Number of downloads: 5
.

--------------------
Microsoft Office 365 (Access) MVP 2017 ->
Go to the top of the page
 
Larry Larsen
post Mar 26 2020, 07:36 AM
Post#4


UA Editor + Utterly Certified
Posts: 24,573
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


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
Attached File(s)
Attached File  ClockInOut.jpg ( 82.95K )Number of downloads: 3
 

--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 
AP_Ben
post Mar 26 2020, 07:57 AM
Post#5



Posts: 54
Joined: 11-February 20



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
Go to the top of the page
 
Larry Larsen
post Mar 26 2020, 08:38 AM
Post#6


UA Editor + Utterly Certified
Posts: 24,573
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


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

--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 
AP_Ben
post Mar 26 2020, 09:10 AM
Post#7



Posts: 54
Joined: 11-February 20



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
This post has been edited by AP_Ben: Mar 26 2020, 09:24 AM
Go to the top of the page
 
Larry Larsen
post Mar 26 2020, 09:24 AM
Post#8


UA Editor + Utterly Certified
Posts: 24,573
Joined: 26-August 02
From: Melton Mowbray,Leicestershire (U.K)


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
Attached File(s)
Attached File  Demo_TimeclockStamp_2020.zip ( 39.96K )Number of downloads: 6
 

--------------------
"Time...We have exactly the same number of hours per day that were given to Helen Keller, Pasteur, Michaelangelo, Mother Teresa, Leonardo da Vinci, Thomas Jefferson, and Albert Einstein"
H. Jackson Brown
Go to the top of the page
 
AP_Ben
post Mar 26 2020, 09:30 AM
Post#9



Posts: 54
Joined: 11-February 20



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
Go to the top of the page
 
AP_Ben
post Mar 26 2020, 09:41 AM
Post#10



Posts: 54
Joined: 11-February 20



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

This post has been edited by AP_Ben: Mar 26 2020, 09:42 AM
Go to the top of the page
 
Gustav
post Mar 27 2020, 04:06 AM
Post#11


UtterAccess VIP
Posts: 2,244
Joined: 21-February 07
From: Copenhagen


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")


--------------------
Microsoft Office 365 (Access) MVP 2017 ->
Go to the top of the page
 


Custom Search


RSSSearch   Top   Lo-Fi    29th May 2020 - 11:46 AM