Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Getting Network Date and Time (Access 2003)

    I am working on a transaction database. The PC users have rights to change the time and date on their individual machines. I want to record the exact time and date the transaction was entered per our network servers for audit reasons. How would I code this?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Getting Network Date and Time (Access 2003)

    Welcome to Woody's Lounge!

    See API: Retrieve NT Server's Time on the Access Web. The code is for Windows NT, it should work on Windows 2000 / XP / 2003 too.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting Network Date and Time (Access 2003)

    Hans

    When I run the above code with:

    ?fGetServerTime ("WinXpSer2")

    I get:

    9/12/2005 00:24:48 PM

    it should be 9/12/2005 12:24:48 PM

    Its droping the hours

    Any thoughts?

    John

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Getting Network Date and Time (Access 2003)

    Why don't you single step through the function to see what happens?

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Getting Network Date and Time (Access 2003)

    The function from the Access web doesn't handle time zone differences correctly, and is US-centric. Here is a version that should work better, and independent of system settings. It returns a Date/Time value instead of a String.

    Note: the declarations in the first part of the code remain unchanged.
    <code>
    Public Function fGetServerTime(ByVal strServer As String) As Date
    ' Original author: Dev Ashish, 1999
    ' Modifications: Woody's Lounge, 2005
    Dim tSvrTime As TIME_OF_DAY_INFO, lngRet As Long
    Dim lngPtr As Long
    Dim datOut As Date

    On Error GoTo ExitHere

    If Not Left$(strServer, 2) = "" Then GoTo ExitHere

    strServer = StrConv(strServer, vbUnicode)
    lngRet = apiNetRemoteTOD(strServer, lngPtr)
    If Not lngRet = 0 Then GoTo ExitHere
    Call sapiCopyMemory(tSvrTime, ByVal lngPtr, Len(tSvrTime))

    With tSvrTime
    datOut = DateSerial(.tod_year, .tod_month, .tod_day) + _
    TimeSerial(.tod_hours, .tod_mins, .tod_secs)
    fGetServerTime = DateAdd("n", -.tod_timezone, datOut)
    End With

    ExitHere:
    End Function</code>

  6. #6
    New Lounger
    Join Date
    Sep 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting Network Date and Time (Access 2003)

    When I am compiling the below in the Module1, I am getting this error:

    Compile error: Only comments may appear after End Sub, End Function, or End Property.

    What does this mean? How do I correct it to get it to compile?

    Private Declare Function apiNetRemoteTOD Lib "netapi32" _
    Alias "NetRemoteTOD" _
    (ByVal UncServerName As String, _
    BufferPtr As Long) _
    As Long

    Private Declare Sub sapiCopyMemory Lib "kernel32" _
    Alias "RtlMoveMemory" _
    (hpvDest As Any, _
    hpvSource As Any, _
    ByVal cbCopy As Long)

  7. #7
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Getting Network Date and Time (Access 2003)

    Those declarations, together with the type definition of TIME_OF_DAY_INFO, must be placed at the top of the module, below Option Compare Database and Option Explicit if you have those, but above all Procedures (Subs) and Functions.

  8. #8
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Getting Network Date and Time (Access 2003)

    Perfect.

    Thanks for taking the time.

    John

Posting Permissions

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