Solved

Validate Short Date Setting - Access VBA

Posted on 2014-04-15
9
640 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
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
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

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

In Debugging – Part 1, you learned the basics of the debugging process. You learned how to avoid bugs, as well as how to utilize the Immediate window in the debugging process. This article takes things to the next level by showing you how you can us…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

912 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

14 Experts available now in Live!

Get 1:1 Help Now