Jul 31 2004, 03:40 PM
Is there any way to change the system date from VBA code? I need to go back one month.However, a general solution would be appreciated ie change day/month/year.
Thanks for your help.
Jul 31 2004, 04:04 PM
Date() = #7/31/2004#
or you could use a variable
Date() = dtmYourDate
Jul 31 2004, 07:15 PM
Do you know, Truitt ..... when I saw YOUR example, I thought ... "NO, this would/should throw an error. Changing system date should NOT be that simple (read dangerous)."
Just tried it , and it worked , for BOTH Date (and Time , as I found out via the : Time() = #11:10:00 AM#).
Is this dangerous .... ????? . Not sure, but it does it !!!
Not sure why you would want to, but you learn something new every day.
Jul 31 2004, 09:34 PM
It suprised me too. It was Saturday afternoon and I was bored and just tried it.
I can't think of any legitimate reason to use it, unless you want to set the date/time to match the date/time on another server or website.
Jul 31 2004, 09:42 PM
Just looked at VBA's help and it is a documented method
Date Statement Example
This example uses the Date statement to set the computer system date. In the development environment, the date literal is displayed in short date format using the locale settings of your code.
MyDate = #February 12, 1985# ' Assign a date.
Date = MyDate ' Change system date.
Jul 31 2004, 11:14 PM
Probably not as dangerous as the Shell() command. Setting the date requires specific permissions in MS's business OS's that should prevent unauthorized users from changing the time.
Aug 2 2004, 07:12 AM
I looked at Truitt's example and tried the same thing with time: Time = #6:56:00 AM# and it worked also. I noticed that the example didn't have the () after the date or time. It's another reason to warn people about what names they use in their tables. If you have fields in your tables called Date or Time and try to assign values to them, it seems possible that you could be changing your system settings instead.
Aug 2 2004, 08:34 AM
Good point. It is always nice to have a concrete example of why reserved words should be avoided.
Feb 7 2012, 04:03 AM
Set up a separate machine not connected to corporate LAN with duplicates of your date.
Anything else will force you into trouble.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here