Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

Changing Windows date format from Access

I'm looking for some sample Access code to change the date format in Windows 95/NT under Control Panel... Regional Settings.  

I would like to be able to do the following:
1.   Check the current short date format
2.   If it's not a 4-digit format, ask the user if it's OK to change it.
3.   Change the format to MM/DD/YYYY

I'm assuming I'll need some API calls, but I don't know where to start.

Any ideas?
  • 3
  • 2
  • 2
  • +2
1 Solution
Victor SpiridonovCommented:
What is  the reason for that?
I agree with spiridinovs question.

You should be able to do all the formatting you want in the table fields, form and report controls. Also the user will not always be too happy to have their settings changed "for no apparent reason"

Are you looking to change the date format in regional settings or simply overide them in MS Access?
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

slpatchesAuthor Commented:
Trygve: By with the default Windows setting, Access only displays two digits of the year.  I get way too many support calls from people wondering why a particular record didn't get processed.  I have them change the date format, and I find that they've entered something like "2998" instead of "1998".

Note also that I'm not changing it "for no reason".  My question stated that I would ask the user to confirm this change.  This same message could explain the reasons.  Y2K ambiguity, etc.

Dev: I'm looking to change it in regional settings.  With the Y2K coming up fast, I believe that a 4-digit year should be the default for all applications.

P.S.  Sorry it took me so long to respond.  I was out of town on business.

Who cares if it's a good idea, I need the points :)

Put this in declarations of your form

Private Declare Function SetLocaleInfo Lib "kernel32" Alias "SetLocaleInfoA" (ByVal Locale As Long, ByVal LCType As _
          Long, ByVal lpLCData As String) As Boolean
Private Declare Function PostMessage Lib "user32" Alias _
          "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
          ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetSystemDefaultLCID Lib "kernel32" _
          () As Long

and put this behind the click event of a command button

Dim dwLCID As Long
         dwLCID = GetSystemDefaultLCID()
'check existing format here. If it's not how you want it prompt for change and do....        

 If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "dd-MMM-yy") _
            = False Then
            MsgBox "Failed"
            Exit Sub
         End If

OK I admit it, I got this from article ID: Q168793 in MSDN. But I tested it and it works.
slpatches: You can format your fields on forms and reports to any format you like 2 digits, 4 digits, you name it. Just select the format property and you will be presented with a list of options.
slpatchesAuthor Commented:
Helicopter:  Thanks for the reply.  The part that sets the format seems to work OK.  However, it's not clear to me how I check the existing date format.

The value of dwLCID seems to be a number such as 1033.  How to I retrieve the actual format being used?

Sorry, I was being lazy.

Put this in declarations:
Private Declare Function GetLocaleInfo& Lib "kernel32" Alias "GetLocaleInfoA" _
(ByVal Locale As Long, ByVal LCType As _
          Long, ByVal LPLCData As String, ByVal cchData As Long)

Then call it using
Dim dwLCID As Long
dwLCID = GetSystemDefaultLCID()

dim buffer as string * 100

If you now print buffer it will give you your short date format, or you can use x which gives you the length of the date format (12 in my case)

slpatchesAuthor Commented:
Excellent!  Works great.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now