Solved

Changing Windows date format from Access

Posted on 1998-06-16
9
204 Views
Last Modified: 2012-05-04
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?
0
Comment
Question by:slpatches
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 7

Expert Comment

by:spiridonov
ID: 1975416
What is  the reason for that?
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1975417
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"
0
 

Expert Comment

by:Dev061798
ID: 1975418
slpatches,

Are you looking to change the date format in regional settings or simply overide them in MS Access?
0
 
LVL 3

Author Comment

by:slpatches
ID: 1975419
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.

-S
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 8

Accepted Solution

by:
Helicopter earned 100 total points
ID: 1975420
Who cares if it's a good idea, I need the points :)

Put this in declarations of your form

Private Const LOCALE_SSHORTDATE = &H1F
Private Const WM_SETTINGCHANGE = &H1A
Private Const HWND_BROADCAST = &HFFFF&
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
         PostMessage HWND_BROADCAST,WM_SETTINGCHANGE, 0, 0


OK I admit it, I got this from article ID: Q168793 in MSDN. But I tested it and it works.
0
 
LVL 12

Expert Comment

by:Trygve
ID: 1975421
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.
0
 
LVL 3

Author Comment

by:slpatches
ID: 1975422
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?

Thanks
0
 
LVL 8

Expert Comment

by:Helicopter
ID: 1975423
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
x=getlocaleinfo&(dwLCID,LOCALE_SSHORTDATE,buffer,99)

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)


0
 
LVL 3

Author Comment

by:slpatches
ID: 1975424
Excellent!  Works great.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now