Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing Windows date format from Access

Posted on 1998-06-16
9
Medium Priority
?
262 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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
 
LVL 8

Accepted Solution

by:
Helicopter earned 400 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

715 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