• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 689
  • Last Modified:

Validate Short Date Setting - Access VBA

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
reportingdude
Asked:
reportingdude
  • 3
  • 3
  • 3
2 Solutions
 
PatHartmanCommented:
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
 
Gustav BrockCIOCommented:
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
 
PatHartmanCommented:
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
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
reportingdudeAuthor Commented:
Yes, the regional date settings vary by machine which is the root of the problem.
0
 
Gustav BrockCIOCommented:
No, the root of the problem is that the application is sensitivity to this.

/gustav
0
 
reportingdudeAuthor Commented:
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
 
PatHartmanCommented:
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
 
Gustav BrockCIOCommented:
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
 
reportingdudeAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now