My Assistant
![]() ![]() |
|
|
Jul 31 2004, 03:40 PM
Post
#1
|
|
|
UtterAccess Enthusiast Posts: 76 From: Canada |
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
Post
#2
|
|
|
Retired Moderator Posts: 13,544 From: Texas (Is there anywhere else?) |
How about
Date() = #7/31/2004# or you could use a variable Date() = dtmYourDate |
|
|
|
Jul 31 2004, 07:15 PM
Post
#3
|
|
|
UtterAccess VIP Posts: 3,752 From: Australia (NSW) |
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
Post
#4
|
|
|
Retired Moderator Posts: 13,544 From: Texas (Is there anywhere else?) |
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
Post
#5
|
|
|
Retired Moderator Posts: 13,544 From: Texas (Is there anywhere else?) |
Just looked at VBA's help and it is a documented method
QUOTE 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. Dim MyDate MyDate = #February 12, 1985# ' Assign a date. Date = MyDate ' Change system date. |
|
|
|
Jul 31 2004, 11:14 PM
Post
#6
|
|
|
Retired Moderator Posts: 11,289 From: Milwaukee, WI |
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
Post
#7
|
|
|
UtterAccess Guru Posts: 989 From: Kansas City, MO, USA |
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
Post
#8
|
|
|
Retired Moderator Posts: 13,544 From: Texas (Is there anywhere else?) |
Good point. It is always nice to have a concrete example of why reserved words should be avoided.
|
|
|
|
Feb 7 2012, 04:03 AM
Post
#9
|
|
|
UtterAccess VIP Posts: 1,823 |
Set up a separate machine not connected to corporate LAN with duplicates of your date.
Anything else will force you into trouble. /gustav |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 21st May 2013 - 04:49 PM |