Consulting

Results 1 to 6 of 6

Thread: VBA help to update t_User_Logs with current user log information

  1. #1
    VBAX Regular
    Joined
    Jul 2017
    Posts
    18
    Location

    VBA help to update t_User_Logs with current user log information



    I am using: Access 2016, 32 bit, and Windows 10, 64 bit.

    Please see attached database User Logging Master v 6.zip

    A splash screen named f_About adds the current Computer machine name as well as the current Windows User Logged in to their respective tables: t_Computers and t_Windows_Users IF they are not already listed. These functions are named: WINUserUpdate and ComputerUpdate and are called on the forms Open event.

    After Logon, f_Logon has the visibility property set to "False" normally after logging in. I am setting it to "visible" so you can see what information I have sitting in fields which are also set to invisible as well.

    So, you can see after logon that I have the ingredients for t_User_Logs...

    My goal is for t_User_Logs to be updated with the current Computers_ID, Windows_Users_ID, Users_ID, Log on Date/Time and Log/Off Date/Time.

    I am not sure which event I would use after the Logon Form has gone invisible to record all of the t_User_Logs information, and how I would add the Computers_ID and Windows_Users_ID and not their names into the t_Users_Logs.

    I am very new to VBA, but was able to get the Computer Name and Windows User name to be pouplated in their respective tables, however I do not know where or how to add their respective ID's to t_User_Logs.

    Thank you for any help you might be able to provide... I would say what I have tried but I really do not have a clue where to start...

    Bill

  2. #2
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Bill, your code has a few bugs in it and the exit button did not work, so I changed it to VBA code.
    For one thing if there is nothing in either of the fields then the SQL crashes, so you need a check in there that ensures that the Fields are not Null.
    I would peronally use VBA Recordsets for adding the data to the tables rather than SQL.
    What is supposed to happen once you have logged in, I can see an Administrator background opens, but what then?

  3. #3
    VBAX Regular
    Joined
    Jul 2017
    Posts
    18
    Location

    Overview of Process

    Quote Originally Posted by OBP View Post
    Bill, your code has a few bugs in it and the exit button did not work, so I changed it to VBA code.
    For one thing if there is nothing in either of the fields then the SQL crashes, so you need a check in there that ensures that the Fields are not Null.
    I would peronally use VBA Recordsets for adding the data to the tables rather than SQL.
    What is supposed to happen once you have logged in, I can see an Administrator background opens, but what then?
    I am not near a computer right now but I did not experience any crashes...I will look tomorrow to see what I did...

    The logging procedures goal is to gather all of the computer names and windows network IDs, add them to their respective tables, ( IF THEY ARE NOT ALREADY WRITTEN THERE )then, on logon, they are added as foreign keys to the t_User_Logs as well as the CURRENT user logged in t this access database....


    As you noticed, once logged on one of two forms is loaded, Administration and the other which I did jot include is the scan Operators Form. I did not add this next level of complexity so I could concentrate on how to solve the issue of writing the foreign keys on login...

    Finally, I then want to write the t_User_Logs_ID to a Temp vars so that when a batch of scans are created the temp vars User_Logs_ID (?will get written to the t_Runs as a foreign key. t_Runs is not included in the sample database as I was tring to keep things simple for me...

    Will repost the working version tomorrow....

    Thanks for your help!

    Bill

  4. #4
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Now that I have looked at you database again, especially the Modules I can see that you are using Recordsets to write the Computer Name and the Windows user ID to their tables.
    So you know how to do it.
    You could add the Log In data to the t_User_Logs in the Password After Update Event after your verification code.
    Obviously the log out data has to be added when the user closes the database, whichever form you will be using for that purpose.
    Last edited by OBP; 08-07-2017 at 11:25 AM.

  5. #5
    VBAX Regular
    Joined
    Jul 2017
    Posts
    18
    Location
    Darn I wish it were true that I know what to do... I've managed to stick some things I found on the net together...but I just do not know how to get the computer and Windows Users IDs from their respective tables without a where clause or lookup or something this noob doesn't know exists...

    So, are you saying I can do this with a recordset ?

    Something like this:

    Public Function ComputerUpdate()
    
    Dim sComputername As String
    Dim db As DAO.Database
    Dim r As DAO.Recordset
    
    
    Set db = CurrentDb
       Set r = db.OpenRecordset("t_Computers", dbOpenDynaset)
          r.FindFirst "Computer_Name='" & ComputerName() & "'"
       If r.NoMatch Then
          r.AddNew
          r!Computer_Name = ComputerName()
          r.Update
    End If
    'Is this where I would add something a DLookup to find the table _ID that matches the computer name currently in use and create a tempvars so I can insert them in t_User_Logs???
       r.Close
    End Function
    I have been at this all weekend and I am pretty well done... if you can help/guide me I would really, really appreciate it as I have had no success doing what I want to do...

    Thanks,

    Bill

  6. #6
    VBAX Guru
    Joined
    Mar 2005
    Posts
    3,296
    Location
    Bill, explain to me what data you want to go where and I will show you how to do it.
    Your code looks ok, does it work?
    Why tempvar, why not a public variable which can be shared by all objects?

    ps can you private mail me?

Tags for this Thread

Posting Permissions

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