Getting time since last restart in VBA of MS Access

Experts,

I'm looking for ways to retrieve time since last restart in VBA of MS Access.
If you can think of several ways to do it - please let me know.

Thank you.
LVL 1
PTishyn_comAsked:
Who is Participating?
 
rockiroadsConnect With a Mentor Commented:
this code returns the date and time in one string

    Set objWMIService = GetObject("winmgmts://./root/cimv2")
    Set colItems = objWMIService.ExecQuery("Select * from Win32_ComputerSystem", , 48)
    For Each objItem In colItems
        strComputer = objItem.Name
    Next

    On Error Resume Next

    Set objWMIService = GetObject("winmgmts://" & strComputer & "/root/cimv2")
    If Err.Number > 0 Then
        Debug.Print "Bugger, summat is messed up"
    Else
        Set colItems = objWMIService.ExecQuery("Select * from Win32_OperatingSystem", , 48)
        For Each objItem In colItems
            Debug.Print objItem.LastBootUpTime
        Next
    End If


Its then a case of splitting it up
0
 
rockiroadsCommented:
what do you mean by restart of vba. Are you talking about the time your access db is started or when one goes to the vba window to do coding etc
0
 
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform)Commented:
"If you can think of several ways to do it "

Even ONE way would be cool, right ?

mx
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
rockiroadsCommented:
wotcha mx. PT, I would suggest a table which stores the time. Add in other attributes, say per user etc etc etc
Each time you start msaccess, you can run the Autostart macro to add in records

This way u have logged when db started. If you have or main menu/switchboard which is automatically started and db closes from that then you can control the login and logout times from here as well

when you login, u can query the db then calculate the date/time difference between that date and Now()
0
 
PTishyn_comAuthor Commented:
I apologize, I wasn't clear.
Time since the computer was restarted or, to be precise, when user logged on to Windows (not since Access was open).
0
 
rockiroadsConnect With a Mentor Commented:
how to split up

        For Each objItem In colItems
            d = DateSerial(Left$(objItem.LastBootUpTime, 4), Mid$(objItem.LastBootUpTime, 5, 2), Mid$(objItem.LastBootUpTime, 7, 2)) & " " & TimeSerial(Mid$(objItem.LastBootUpTime, 9, 2), Mid$(objItem.LastBootUpTime, 11, 2), Mid$(objItem.LastBootUpTime, 13, 2))
            Debug.Print d
        Next

0
 
rockiroadsCommented:
by the way, this is time since pc boot up
0
 
PTishyn_comAuthor Commented:
Thank you very much.
0
All Courses

From novice to tech pro — start learning today.