Results 1 to 8 of 8
  1. #1
    PeterF
    Guest

    Time Statement and Function (Word 2000)

    Word 2000 VBA Help:
    - tells me that the Time Function returns a Variant (Date) indicating the current system time
    - says to use the Time statement to set the system time.

    I am using Time in a macro:
    Dim MyTime
    MyTime = Time

    MyTime is returning values like:
    1899-12-30 18:35:55
    in which the date is obviously incorrect and the time is correct.

    1. Does anyone know how to set the current system time to return both the correct date and time? For example:
    2001-08-19 18:35:55

    2. Can I change the time permanently - will the change "stick"?

    3. Are there any unwelcome consequences from adjusting the current system time from its default setting?

    Thanks in advance for your assistance
    Peterf

  2. #2
    5 Star Lounger
    Join Date
    Dec 2000
    Location
    Tallahassee, Florida, USA
    Posts
    901
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Time Statement and Function (Word 2000)

    Hi, PeterF!

    To set the current date/time -- double-click on the time showing (on most computers anyway) in the lower right of your screen. There will be 2 tabs (at least on my Win98 version): Date & Time and Time Zone. If you figured out any VBA, you'll figure those out with ease. Once you've done that, you may want to check for freeware or software (I use Atom Time) to keep your computer clock synchronized. There are probably some links and recommendations in the Software forum here.

    As to the format, I think the macro is picking that up from Word. Go to Insert / Time and set it how you want it to look. I know there's a way to format it programatically so that if you change that setting the macro will still format to your specifications, but I'm without my books at home.

    HTH
    Karen

  3. #3
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Time Statement and Function (Word 2000)

    I can't duplicate the problem. Presumably that funky date is being interpreted in my copy of Word 2000 to mean "ignore this part" because all I get is the time value (in the Locals window, or if I use Debug.Print myTime). Are you taking this value over to a "date/time" field in Access or another database? Perhaps that application is not ignoring the bogus date portion.

    If you actually want the full date and time, use myTime = Now. (There's something poetic about that. <img src=/S/smile.gif border=0 alt=smile width=15 height=15>) Hope this helps.

  4. #4
    BAM
    Guest

    Re: Time Statement and Function (Word 2000)

    Hi PeterF,

    We might need a little more of your code to see where the problem lies.

    For example :
    <pre>Dim MyTime
    MyTime = Time
    Debug.Print MyTime
    </pre>

    Returns the system time. So the question here is, where are you using MyTime in your code? I believe that is where the problem lies.
    ~~~~~~~~~~~~~
    Cheers! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  5. #5
    PeterF
    Guest

    Re: Time Statement and Function (Word 2000)

    Thank you for replying KB MacKenzie.

    I have checked the date value in the Windows 98 Date/Time Properties dialog and the correct date is displayed.


    Thank you for replying jscher2000 and BAM.

    I think I had better tell you more about what I am doing. I am writing user-initiated macro events to a log file. For example, the user makes a choice and the macro does something. Then it writes a record of what it just did to a log:
    <pre> Open "C:My Documentsmacro_log.txt" For Append As #1
    Write #1, "Option 1 chosen.",
    Write #1,
    Write #1, "Date & Time:"; MyTime
    Write #1,
    Close #1
    </pre>

    And I am getting output like:

    <pre>"Option 1 chosen.",
    "Date & Time:",#1899-12-30 23:17:12#
    </pre>

    Thanks in advance for your cogitations, and any further suggestions you may have.

    PeterF

  6. #6
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Time Statement and Function (Word 2000)

    Time() returns just the time and a date value of 0 which is December 31, 1899. Date() returns just a date and a time value of zero which is midnight. Now() returns both date and time. Try:

    <pre>Dim MyTime As Date
    MtTime = Now
    </pre>

    Legare Coleman

  7. #7
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Time Statement and Function (Word 2000)

    Try changing

    Write #1, "Date & Time:"; MyTime

    to

    Write #1, "Date & Time:"; Now()

  8. #8
    PeterF
    Guest

    Re: Time Statement and Function (Word 2000)

    Thank you Legare for explaining the differences between Date, Time and Now.

    Thank you jscher2000 for your solution, which I have used successfully. Using the function Now() seemed to be the simplest way to go, and allowed me to dispense altogether with declaring a variable .

    PeterF

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •