Finding OS short date format string in MS-Access/VBA

天大地大妈咪最大 提交于 2021-01-29 18:30:52

问题


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:


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



来源:https://stackoverflow.com/questions/59460034/finding-os-short-date-format-string-in-ms-access-vba

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!