Solved

Validate Short Date Setting - Access VBA

Posted on 2014-04-15
9
638 Views
Last Modified: 2014-04-16
Is there a function I can use within Access to see what the short date settings are?  If the short date settings are NOT MM/dd/yyyy I want to prompt the user to change the settings.

Not all of the machines within my company are configured the same way and the differing formats are causing some issues with a database I inherited.

I have sent directions to have users validate the settings, but am still running into this issue, so I would like to throw something onto the main menu that will stop them from proceeding unless the short date settings are MM/dd/yyyy
0
Comment
Question by:reportingdude
  • 3
  • 3
  • 3
9 Comments
 
LVL 34

Expert Comment

by:PatHartman
ID: 40001901
I don't have an answer for you but since the date format is a Windows setting, I would search for a Windows API that controls them and that may allow you to change the setting.

I did find this function - GetDateFormat()
http://msdn.microsoft.com/en-us/library/dd318088(v=vs.85).aspx
You can examine the return value to determine if it is what you want.  So just use the left, Mid, and Right functions to extract what would be the month, day, and year if the return value was formatted as a short date.  If the result doesn't produce a valid date, then the system date format is not short date.
0
 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40001938
This is the wrong way.

User's preferences are - exactly - the user's preferences, not yours.
No matter what, if your application has "issues" because of this, the better way is to correct your code where you experience troubles. It is not difficult at all.

If your application for some reason must display or print using a specific date format, all you need is to apply this format in those cases.

/gustav
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 40002123
I agree Gus but in this particular case, the changed setting is almost always a user mistake.  It is best if we can control the date format with a "named" format such as Short Date because we want Windows to control it based on its regional settings.  It would be a lot of work to modify every control that displays a date to have a specific format such as mm/dd/yy.  It would also mean that the app would only work for a locality where that date format is standard.
0
 

Author Comment

by:reportingdude
ID: 40002268
Yes, the regional date settings vary by machine which is the root of the problem.
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 49

Expert Comment

by:Gustav Brock
ID: 40002541
No, the root of the problem is that the application is sensitivity to this.

/gustav
0
 

Author Comment

by:reportingdude
ID: 40002568
As I said this is an inherited database with hundreds of controls.  Sometimes it is easier to do things quickly and move on to the next project rather than doing things the "correct" way.  

The tables should be restructured to to be correct, but the tool works and I have more pressing things to work on.  I was asking for a bit of code that would allow me to see what the short date was set to in case you missed the original question.
0
 
LVL 34

Assisted Solution

by:PatHartman
PatHartman earned 100 total points
ID: 40002605
Gus, the sensitivity is most likely visual.  4/15/14 takes up far less room than Tuesday, March 15th, 2014.  When the short date format is "long" the date will not fit into the space allocated on forms and reports and it will show as #####.  It will still work on a form.  It is just that the user will not be able to see it unless he clicks into the control.  For reports, you can set the can grow property and make it wrap to two lines.

@reportingdude,
Did you try the code I posted?
0
 
LVL 49

Accepted Solution

by:
Gustav Brock earned 400 total points
ID: 40003298
As I guess you really don't care what format the user may have as his/her preference, then why not just use:

datTest = #12/31/1999#
If Format(datTest, "Short Date") <> Format(datTest, "mm/dd/yyyy") Then
    ' Prompt user.
End If

/gustav
0
 

Author Closing Comment

by:reportingdude
ID: 40004238
Gustav, your code worked!!  I just changed the "datTest" date since the issue was popping up with months or days in single digits (ie January being 1 and not 01) I tested after changing my short date settings on the control panel and its working.  Set it up to open a subform with instructions for fixing the date settings.
Pat, thanks for clarifying my question.

Private Sub Form_Load()
datTest = #1/1/1999#
If Format(datTest, "Short Date") <> Format(datTest, "mm/dd/yyyy") Then
DoCmd.OpenForm "SF_FixDate", acNormal, "", "", , acNormal
End If


End Sub
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

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…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

708 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