Solved

Changing Windows date format from Access

Posted on 1998-06-16
9
217 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Create Form using Wizard 14 39
Problem with syntax with TransferDatabase 3 15
I need to be able to get MAX(date)-1 from table. 4 28
error 3022 in access vba 3 18
In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

863 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

25 Experts available now in Live!

Get 1:1 Help Now