I'm having this frustrating problem in Access. I have a form with a text box control, formatted as hh:nn. However, if the time has a single digit hour, such as the time 08:45, when I leave the text box Access seems to change the format to h:nn, displaying only 8:45.
This causes difficulties the next time a user enters the text box and tries to change the time or even just leave the time as is.
Why is Access displaying the hh:nn format as h:nn? How can I fix this?
I had the same issue because of "the regional Long Time format" as explained in the below reference.
Reference
My regional Long Time format was set to "h:mm:ss tt". I changed it to "hh:mm:ss tt", exited Access, restarted and reopened the test database I was using, and now the dates, in table and form, are displaying the hour with the leading zero.
Related
My table field is date/time and formatted like this:
mm/dd/yyyy hh:nn:ss
I want the user to see this (with the space appearing between date and time
__/__/__ __:__:__
I want an input mask that demands:
Either 1 or 2 digits for the month
Either 1 or 2 digits for the dat
All 4 digits for the year
SHOWS the space but just jumps over it for the user
Either 1 or 2 digits for each of Hours, Minutes and Seconds
Further, when setting up a DB, is it just smarter to have two separate fields for Date and Time. A collegue encouraged me to break them out ... seems sensible?
00/00/0000##00:00:00
See the outcome in the image
Controlled user input is not an easy task in Access, as it is optimised for the opposite: To be tolerant and accept many input sequences for date and time.
For the cases where controlled input is mandatory, I've written two articles including full code (too much to post here) and demo, that may give you some ideas:
Entering ISO formatted date with input mask and full validation in Microsoft Access
Current code at VBA.DateEntry.
and
Entering 24-hour time with input mask and full validation in Microsoft Access.
Current code at VBA.TimeEntry.
So I have a couple tables that I want to filter on their Date/Time fields. Here's a snapshot of the form controls that I'm experimenting with.
This will report will probably end up run on a monthly basis, and so the filter "Between Forms!Sorting!OldestDate and Forms!Sorting!NewestDate" will normally work fine. However, sometimes it's useful to just run it on a single day, as in the picture, in which case I need the filter to work out to "Between #M/D/YYYY 0:00:00# and #M/D/YYYY 23:59:59#". Setting up the format on the controls to actually record the time as well as the date, however, has not been working out.
I thought, first, maybe the time wasn't displaying bc my text boxes were too small, so I tried adding the bottom text box. The display in the snapshot is what I desire, however, if I click out of the text box the date disappears and only the time is displayed. It also does not display any time at all until I go in and manually add a time.
Is there a way to force the display of both the short date and the long time? Or is there a way to, say, set the default TimeValue for NewestDate to 23:59:59?
Right now the only "solution" I might have is CVDate(CDbl(Forms!Sorting!NewestDate)+0.99999) appearing multiple times in my WHERE clause, which will make things harder to keep track of or catch mistakes in.
I have vba experience, though I've never tried to use it to mask/edit a form parameter as it is passed to a query. I am using Access through MS Office Professional Plus 2019.
First, in your query, specify as parameters:
[Forms]![Sorting]![OldestDate] DateTime,
[Forms]![Sorting]![NewestDate] DateTime;
Then you can filter on:
[YourDateField] >= [Forms]![Sorting]![OldestDate] And [YourDateField] < DateAdd("d", [Forms]![Sorting]![NewestDate])
If [YourDateField] is text, change that to DateTime. If that is not possible (it should be), use:
DateValue([YourDateField])
I set the date/time format and Input Mask in a field to display/input a 24 hour format Dec-28-2006 # 12:12 but when I edit the field with an existing date it reverts back to Dec/28/2006 12:12:00 PM.
Format is set to "mmm-dd-yyyy # hh:nn
Input Mask is set to ">L
I need to keep the field in this mode (Dec-28-2006 # 12:12) when editing an existing date/time. Is this possible?
That is by design, and it takes a lot to make it behave differently.
You may get some inspiration from my two articles and their demo applications:
Entering ISO formatted date with input mask and full validation in Microsoft Access
Entering 24-hour time with input mask and full validation in Microsoft Access
If you don't have an account, browse for the link: Read the full article.
Too much code to post here, but code is also on GitHub: VBA.DateEntry and VBA.TimeEntry.
This is specifically for MS-Access Web Databases (requires Sharepoint hosting) which has many limitations compared to their client counterparts, like no VBA, instead you get form macros and data macros to manage data.
I've run into a weird bug on one of my applications. I have a query used to check stock levels against a "minimum stock level" also saved in the table. The query is pretty intense and there are over 4,000 records now to check against. These querys normally take about 75s. So I have made a little label that gets updated every time the form is loaded showing the time and date the query was last run, and the duration in seconds it took. (so users can see how fresh the data is and decide if it needs to be run again)
Now, the weird thing is it works fine in my Access client, but when I sync my changes to the server and try it in a web browser I get a "type mismatch" error. A small table is used to store the start and end times whenever the query is run, that's how I get the timestamp data. These fields are in a "Date/Time" format, obviously. But it seems the problem here is changing the date format to a string format so it can be put in a label on the form. The Access client seems perfectly capable of doing this, while the web client stumbles and falls.
My problem is, how do I change data in a date/time format to a string format in a Web database? I can't figure out how to do this. The tools are so limited. I may have to end up answering my own question here but I'm posting this for others just in case.
To return a value from a data macro as string, you have to format the internal date/time format as a string. In Access an internal date/time value is a double number with the integer part as number of days since 1900, and the “decimal” time part is a fraction of 24 hours. Unfortunately if you simply wrap the date/time in the str$() function we had for 20+ years, then you get something JUST like if you type this into the debug window:
? cdbl(now())
41955.5478587963
The solution is to simply pull out each part. And “nice” is while in few cases a data macro will cast the data type, it does in this case and thus the STR$() command is not required.
The expression you thus can use is this:
Month([d]) & "/" & Day([d]) & " Time = " & Hour([d]) & ":" & Minute([d])
So say to pluck out the VERY LAST start time column from say a invoice table, since we don’t have a dmax(), then we simply sort the table in the order we want and pull out the first row.
Our data macro will thus look like:
Note how in above I simply typed in the SQL and SET the order on the date/time column. I want the MOST recent invoice start date and time. For those new to SQL, then I suggest you build a query in the query builder and specify a query in above lookup feature, since many are not "comfortable" typing in free hand SQL as I did above.
Now, in your browser side (UI) macro, you can use this code:
The above returns a formatted string that you can stuff into a text box, or as per above code change the caption of a label.
Unfortunately with silly problems like this, it becomes a path-of-least resistance thing.
Since my intended result was simply to get "a timedatestamp from a table to show up on a form (so users could see when a query was last run)", this became redesigning my form in Access to be a text field instead of a label. Text fields can be adjusted to accept "Time/Date" formats, so this is exactly what I did, it now pulls the timestamp data directly from the last record of the table and requires no extra formatting to appear in the web browser. I redesigned the text field to appear and function more like a label, and my desired function was achieved.
However, since my question specifically asks, "how do you change a time/date format into a string format in a Web db?", I will leave it here in case someone actually does solve it.
I have a strange phenomen I can't explain nor reproduce and I'm hoping you have an idea how it was possible for the user to enter an invalid value.
I have an Access-MDB with a form containing an edit field that should only accept time values without any date-information.
The relevant properties of that edit field are as below:
bound to a Date/Time database value (since access know no time-only datatype)
Format: "Time, 24hrs"
Input Format: "99:99"
(I use the german version of Access, so the property names may be a little different, but you see the pattern)
Now I found out that a user was able to enter a date value into that field. I'm nearly 100% sure that it was an accident and no "clever hack" in the form of directly opening the table and editing the corresponding Date/Time field. Since the entry was made back in 2009 (nobody spotted the error), I have no chance to ask the user how it was done.
I found two wrong entries with the dates "01.06.2000" and "01.07.2000" and I guess the user wanted to enter the times "06:00" and "07:00".
I tried every input I can imagine (like "6.0", "6;0", "6,0", copy&paste) but I was unable to trick access and enter anything except digits and the colon.
Do you have any idea what is going on and how the user was able to enter these dates accidentially?
A Jet/ACE Date/Time value is never stored "without any date information". If you attempt to store only the time component, it will actually be stored with the same time on day zero (Dec 30, 1899).
We can only speculate how the incorrect data was added back in 2009. If you want the database engine to require your Date/Time values to be stored with day zero as the date component, you can add a table-level validation rule. From the table property sheet, try this for Validation Rule:
DateValue([your_date_field])=CDate("1899/12/30")
If you want to allow Null for your_date_field, try this version:
IsNull([your_date_field]) Or DateValue([your_date_field])=CDate("1899/12/30")
Several possibilities:
A developer (you?) did it by accident when looking at the raw table
The client Access software went momentarily crazy and corrupted the entry. This has happen to us (fortunately very rarely) where our Access tables will end up with non-ASCII characters in a string field.
A bug in Access runtime allowed the problem in the past, but has been corrected in a service pack.
Finally, if you put in 90 hours, does it overflow into 4 days and something? That might do it.