Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Script to Change Format

Posted on 2012-12-20
13
Medium Priority
?
461 Views
Last Modified: 2012-12-21
Hi Experts,

Is it possible to write a VBA Code to check if the system's Short Date format is mm/dd/yyyy, and change it if isnt?

Thank you
0
Comment
Question by:APD_Toronto
[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
  • 4
  • 3
  • 2
  • +3
13 Comments
 
LVL 75
ID: 38710662
Just a comment - as opposed to a solution.
Seems doing so could really piss off a user(s) who wants that Format.

Instead, why not hard code the format you want to display in a Control's Format property and/or in code.  This will override the Windows whatever format.

This is what I do ... as I prefer mm-dd-yyyy

mx
0
 

Author Comment

by:APD_Toronto
ID: 38710692
pissing off the user would be a bonus :)

the application is huge, and dates are used in literaly 100s of places, so my solution above is most economical.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38710981
<the application is huge, and dates are used in literaly 100s of places, so my solution above is most economical. >
By "100s of places", ...do you mean geographic locations?
(different countries)
Because changing this for all computers in all countries may cause problems...
There may be some utilities installed on some machines that need a different date setting...

Is there a specific issue you are having...?
Like MX, I am just a bit wary of just blowing though and making this change for all computers...
...When a change to the date format in Access may be all that is really needed...


In any event, a link to investigate:
http://en.allexperts.com/q/Excel-1059/2010/9/change-Regional-Setting-short.htm

JeffCoachman
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

Author Comment

by:APD_Toronto
ID: 38711418
Because changing this for all computers in all countries may cause problems...

WOW.  It's one office, 300 sqft with 7-10 PCs.  

What i meant by 100 places was, something like 30 forms + 50 sub routines + 20 queries = 100 places
0
 
LVL 75
ID: 38711435
Just curious ... does the Format really matter since it has not bearing on how the date is actually stored in a table internally ?
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 38711813
MX,

I'll leave this to you...
I gotta get started on the Holiday stuff...
;-)

Jeff
0
 
LVL 65

Accepted Solution

by:
RobSampson earned 2000 total points
ID: 38711937
Hi, I guess it's up to you whether you want to make your system more robust, or just force the change of the "short date format" by using this code:

Set objShell = CreateObject("WScript.Shell")
sDateFormat = objShell.RegRead("HKCU\Control Panel\International\sShortDate")
If sDateFormat <> "mm/dd/yyyy" Then objShell.RegWrite "HKCU\Control Panel\International\sShortDate", "mm/dd/yyyy", "REG_SZ"

Open in new window


Regards,

Rob.
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 38712340
You have to deal with possible different Windows settings for the users, as in a properly set up environment, users will not have been granted permission to change the date and time settings.

The method is simple; whenever a date/time is displayed, set the Format property of the textbox to: mm/dd/yyyy

/gustav
0
 
LVL 9

Expert Comment

by:shorvath
ID: 38713461
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


Sub chgDate()
Dim dwLCID As Long
Dim myDate As String
       
dwLCID = GetSystemDefaultLCID()
       
       
If SetLocaleInfo(dwLCID, LOCALE_SSHORTDATE, "dd/MM/yyyy") = False Then
     MsgBox "Failed"
     Exit Sub
End If
PostMessage HWND_BROADCAST, WM_SETTINGCHANGE, 0, 0
       
End Sub
0
 
LVL 75
ID: 38713696
"as in a properly set up environment, users will not have been granted permission to change the date and time settings."
Especially at our LARGE company now that Win7 is being deployed ... total lock down ... barely can write to Registry at all.

mx
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 38713719
Yeah, same goes for changing screen resolution - popular in the days of CRT monitors - a big no-no.

/gustav
0
 
LVL 75
ID: 38713754
Well .. users here can manually change screen res of course ... many still use 800x600 on 24" dual monitors!  Can you say"  I cant' see' !
0
 
LVL 52

Expert Comment

by:Gustav Brock
ID: 38713773
Really? I haven't seen that on modern flat screen monitors. We always use the default (optimum) resolution.

/gustav
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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 …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

609 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