Solved

Validate Short Date Setting - Access VBA

Posted on 2014-04-15
9
643 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 36

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 50

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 36

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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 

Author Comment

by:reportingdude
ID: 40002268
Yes, the regional date settings vary by machine which is the root of the problem.
0
 
LVL 50

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 36

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 50

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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

Suggested Solutions

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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