Full Version: Change System Date via VBA
UtterAccess Forums > Microsoft® Access > Access Modules
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.
How about
ate() = #7/31/2004#
For you could use a variable
Date() = dtmYourDate
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.
It suprised me too. It was Saturday afternoon and I was bored and just tried it.
Ocan'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.
Just looked at VBA's help and it is a documented method<
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.
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.
Good point. It is always nice to have a concrete example of why reserved words should be avoided.
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 UA. To view the full version with more information, formatting and images, please click here.