Solved

Validate Short Date Setting - Access VBA

Posted on 2014-04-15
9
644 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
[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
  • 3
  • 3
  • 3
9 Comments
 
LVL 37

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 37

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
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 

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 37

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

752 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