I have some forms with a Text Box to enter a time. I'm only interested in hours and minutes. The Format is set to "Short Time" and the input mask to "00:00;0;_"
In most cases, where the default value of the time is null, this works great: you type in the time and it just works.
However, in some cases I preload the text box with the time part of "Now()" as this is a reasonable default. But if the user wants to change it they can.
My problem is that when I get the time part of Now() I get seconds as well (e.g. 14:35:27). It is all loaded into the text box and as soon as you try to change it you get into trouble with the input mask.
Yes, you can delete the S part but this is unnecessarily fiddly for my users (who are not computer literate, so I am trying very hard to make this as easy to use and foolproof as possible).
The "Short Time" format include the seconds in it, so it's normal to have them when you extract the value from the Now() function. You can define your own format and input mask if the predefined ones do not fit your needs.
Thanks for the response, but I think I need more guidance. According to Access Help, Short Time format is defined as hours and minutes only, which is what I want. So the format for the control is set to Short Time (if you try putting hh:nn it just gets changed back to "Short Time"), and the time is initially displayed in that format. But as soon as you click in the box to change something, the seconds appear and, as I say, you are in trouble with the input mask. So how do I stop the seconds appearing when I click in the box?
PS - I should probably add that this is an Unbound control...
Last edited by CeejayDBF; 07-13-10 at 22:11.
Set your default value to =time(), set the format to Short time and set your format to 00:00;0;#.
Time is the time of the system clock.
First, thanks for reminding me of the existence of Time() - I'd quite forgotten and was making my life more complicated than I needed to! Not relevant to this problem though.
My format was already Short Time and I assume you meant the Input Mask should be 00:00;0;# ... well apart from the # instead of _ at the end that's exactly what I have (I did just try # in case there was some magic ... but no!).
So I've done all that and still have the problem. If you tab into the control it stays in the Short Time format of HH:NN and you can type a new value if you want. But if I click into it, the seconds get shown as well...
More ideas, please?
PS: I should say that the problem only appears when you click into the control as the first thing you do. If you tab to the control, type something in, then click in another control, then click in this one - it stays in HH:NN format and all is well. But if I restart the form, and click to the control, the seconds appear again...
Last edited by CeejayDBF; 07-14-10 at 06:03.
Well, here is a partial answer. If I set the input mask to "00:00C99;0;_" then at least the extended version, with seconds included, is valid against the input mask, while the short version is also valid as the seconds part is optional.
Coming back to this old thread of mine ... I let it go previously, but I'm now revisiting this application and trying to tidy up some loose ends, of which this is one. I googled for helpful threads and found my own!! Access 2007.
So let me put the problem a different way...
On a form, I have two unbound text boxes (StartTime and EndTime). Both have the format "Short Time" and both have the input mask "00:00;0;_", and both are initially blank.
When the user enters the StartTime box they see a time in the format hh:nn.
I have AfterUpdate code which adds an hour to that and puts that value in EndTime, as a default value for the user. As expected, it appears there as hh:nn
Now, if the user clicks into the StartTime box then they are editing a field in the format hh:nn and all is well - they type whatever they want.
BUT ... if they click into the EndTime box, the field is suddenly expanded to hh:nn:ss and the users are getting confused... not least because if they just change the minutes value and don't delete the seconds, Access throws out their entry as being badly formatted!
Even more confusing: if they do manage to enter a legal time in EndTime, and then click back into it to change it again, it stays as hh:nn
It appears that the hh:nn:ss is popping up because a calculated value has been put there??
I'd really like to find a way of making sure that the seconds don't keep popping up, and that my users can just enter hh:nn.
Thank you for taking the time to respond, but I don't think you've quite understood my problem.
The text boxes are already unbound - I pick up the values much later, when the user clicks an "OK" button: then I do a lot of checking and if everything is in order I copy these values (among others) to where they have to go.
What is confusing me is that, even though I have set the format as "Short Time", the "EndTime" box will show a value such as "13:26:00" if you click into it ... but only if that value was generated by my code adding an hour to the value of "StartTime" ("12:26" in this example.
If I successfully edit the value in "EndTime" to, say "14:00", click somewhere else and then back into EndTime, I will see "14:00".
Why is it sometimes showing the seconds and sometimes not?
Poppa Smurf: I downloaded your db (thanks!) and of course it works fine. So now I try to track down the difference between yours and mine! One change I made was to the way the hour is added: yours is elegant, mine slightly less so but it ought to work:
end_time = start_time + #01:00:00 AM#
At this point your test DB started showing the same problem as mine, with the seconds appearing in end_time when you click into it! Strange, I think, but never mind: I apply your method of adding an hour to my db and of course it makes no difference, I still have my problem.
I go back to your db, reverse the change, it goes back to normal - put it back again and it stays normal! Now nothing I can do to your test db will break it - but I am certain that I saw the problem at one point. I even tried retracing my exact steps from the time I opened up the ZIP file, but to no avail.
This is the kind of irrational behaviour that is sometimes fixed by a quick Compact and Repair, but no...
So now I turn to chris07tibgs - no I hadn't tried that, but now I have. Now I can see the format flash briefly to, say, 12:34:00 and then back to 12:34.
This is a lot better and, although I still have no idea why this should be necessary, I'll take this as being good enough.
BTW, in case anyone is thinking that there is something broken in this particular form and I should just rebuild it - I have three different forms all showing similar behaviour!
Anyway, I think I'll just take Chris' suggestion and live with a little flash for this time.
Just to add to that in case anyone has any ideas of where this is coming from ... I consistently have the problem whenever I have a text box, formatted as Short Time, where I fill the value with VBA code.
If the box is left empty, or filled by being bound to a table element, or filled by having a value typed in, then it's ok - the next click into the box will show something like "12:34". But if the box is set by a code statement, then the next click in will show something like "12:34:00".
It's as if the Format property is being amended by the VBA code that is writing a value....... even though Poppa Smurf's example shows that not all DBs behave this way!