0
votes

I am looking for a VBA function that would return the current OS Short date format (ex: M/d/yyyy, dd-MMM-yy, yy/MM/dd, etc.) as a string. I have found such functions for MS Excel on related posts using Application.International, but they do not work with MS Access.

I want to be able to show the OS date format in my forms to avoid confusion if '08-11-11' is displayed, for example. Using CDate(), my dates are automatically formatted to whatever is set in Windows Date and time settings. However, users might not be aware of that.

1
You're afraid users won't know what the date format is on their own machines? - Ken White
@KenWhite I'm afraid they would not be fully aware that MS Access uses the same date format as their OS. - MiniG34
Force the format - either via mask in the form or using the format function and listing as a string and label the box to make it clear what the format is - maintaing concistency for all users. docs.microsoft.com/en-us/office/vba/language/reference/… Otherwise if you are dead-set on listing and using OS date format settings - see here. Can be done by using windows API calls. vbforums.com/… - Mike

1 Answers

3
votes

Just pull it from the registry.

There are many ways, the way I use:

CreateObject("WScript.Shell").RegRead("HKCU\Control Panel\International\sShortDate")

Of course, one could use WinAPI to read the registry too.

If reading the registry is really undesirable, you can always format a distinct date, for example:

Format(#2/1/3333#, "Short Date")

And then parse the result to get the format