Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Changing Windows date format from Access

Posted on 1998-06-16
9
Medium Priority
?
272 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:Victor 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
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 
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

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses

772 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