Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2014

    Unanswered: fields auto populating


    Have a form that the employees enter their daily hours in (production based company), I would like to have two fields to auto populate when the employee logs into the db. The two fields are their name and employee ID.

    Currently my db has it when the employee chooses the form it will ask for parameters to add their employee Id several times which I do not want them to do that. I have tried doing look ups to a query as well as a table however it still continues to ask for the parameters.

    Any suggestions or recommendations on how to get the form to open with the information already populated into the fields based off their login.

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 14
    1. Where are the data (employee name and employee ID) stored in the database?
    2. How does an employee identify itself to the system?

    The easiest and surest way to identify who is connected consists in retrieving the user name of the person that opened the Windows session. For that, you can use:
    Dim strUserName As String
    strUserName = Environ$("USERNAME")
    Or you can call an API (temper proof):
    ' In the Declaration section of the Module:
    Public Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long
    Public Function GetNTUser() As String
    ' Retrieve the ID of the currently connected user
        Dim strUserName As String
        Dim lngUserNameSize As Long
        strUserName = String$(255, 0)
        lngUserNameSize = Len(strUserName)
        GetUserName strUserName, lngUserNameSize
        strUserName = Left$(strUserName, lngUserNameSize - 1)
        GetNTUser = strUserName
    End Function
    You can then compare the retrieved name with user names stored into a table if necessary (e.g. to retrieve an ID that's associated with each user).
    Have a nice day!

Posting Permissions

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