Results 1 to 14 of 14
  1. #1
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16

    Translating Windows name into Real Name

    I have my form capturing the windows user name. If I have a table that associates the winusername with a real name is there a way to have access translate that windows name into a real life name and place the "real" name in a text or cbo box on a form?



  2. #2
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    How is Access provided with the winusername?

  3. #3
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    I used theh FOSFunction
    Code:
    Function UserName() As String
        Dim lngLen As Long
        Dim strBuffer As String
        
        Const dhcMaxUserName = 255
        
        strBuffer = Space(dhcMaxUserName)
        lngLen = dhcMaxUserName
        If CBool(GetUserName(strBuffer, lngLen)) Then
            UserName = Left$(strBuffer, lngLen - 1)
        Else
            UserName = "NoUser"
        End If
    End Function

  4. #4
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    assumptions:
    table that contains the info = tblUsers
    field that contains the windows name = winUserName
    field that contains real names = realUserName
    textbox that will hold the realUserName = txtUserName
    the query that txtUserName is bound to = qryUserName

    change the above from the code below to reflect your db
    Code:
    Dim strSQL As String
    Dim qdfNew As DAO.QueryDef
    
    strSQL = "SELECT realUserName FROM tblUsers WHERE winUserName = """ & UserName & """;"
    
    With CurrentDb              
                                       
        .QueryDefs.Delete ("qryUserName")
                                        
        Set qdfNew = .CreateQueryDef ("qryUserName", strSQL)
        .Close
    
    End With
    
    Me.txtUserName.Requery
    Give that a whirl and see what happens.

  5. #5
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    Where in the VB Editor would I place this code? Would this need to be an oncurrent() Event?
    table that contains the info = tbl_employeenames
    field that contains the windows name = winUserName
    field that contains real names = realUserName (I don’t have a field that holds these names, they are stored in my tbl_employeenames)
    textbox that will hold the realUserName = txtUserName
    the query that txtUserName is bound to = qryNames

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Just include it in your UserName() function. put the declarations in with yours and the meat of the code after your "End If"

    Also, you said
    "If I have a table that associates the winusername with a real name"
    However you have it setup, just make the strSQL contain the query that would get it. You set up the VBA, I'm going to assume you can put together a query that would get the join in the right place. Just add the WHERE condition like I had.

  7. #7
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    I get this error message on this line of code:
    Compile Error:
    User-defined type not defined
    Code:
    Dim qdfNew As DAO.QueryDef

  8. #8
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    uhhhhhhhhh.

    try declaring it as just a QueryDef

  9. #9
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    Same thing.

    I changed the code to

    Code:
    Dime qdfNew As QueryDef
    and same error.

  10. #10
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    Also at the bottom of the code I get a message that says Invalid use of Me. Keyword on the

    Code:
    Me.txtUserName.Requery

  11. #11
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    I honestly have no clue why the querydef isnt working. perhaps queryDefs? (add the s)

    And yea, that's right. you cant use Me in your function. it's not a form control. my mistake. just refer to the form control directly.

  12. #12
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    Anyway I input it, it is not liking the queryDefs or queryDef or the DAO.querydefs, DAO.QueryDefs, or DAO.QueryDef????

    Thanks for trying!

  13. #13
    jo15765's Avatar
    jo15765 is offline Expert
    Windows 7 Access 2000
    Join Date
    Nov 2010
    Location
    6 Feet Under
    Posts
    672
    I used this code to get it to work on mine, but of course this was a LostFocus() Event but it works for me.

    Code:
    Dim t_name
        Dim t_cbo_name
        Dim strsql As String
        Dim rst As Recordset
        Dim db As Database
        Dim rec As Recordset
        Set db = CurrentDb
        Set rec = db.OpenRecordset("tbl_john")
        
        Do Until rec.EOF
        With rec
           If Trim(![Windows_Name]) = Trim(Me.txt_winusername) Then
            t_name = ![id]
            t_cbo_name = !Employee_Name
                If IsNull(Me.Record_Input_By) Then
                
                    Me.Record_Input_By = t_cbo_name
                Else
                End If
            
           Else
           
           End If
           .MoveNext
            
        End With
        Loop
        
        Set rec = Nothing
        Me.WinUserName_box = txt_winusername
        Me.date_updated = Now()
       'Debug.Print t_name, Me.txt_winusername, t_cbo_name
      
          DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70
    Exit_issues_LostFocus:
        Exit Sub

  14. #14
    runthis457 is offline Novice
    Windows 7 64bit Access 2000
    Join Date
    Feb 2011
    Posts
    16
    I am getting an error on all the
    Code:
       Dim strsql As String
        Dim rst As Recordset
        Dim db As Database
    Is it possible to do what I am after?
    Dim rec As Recordset

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 07-15-2010, 05:53 PM
  2. real time clock
    By krai in forum Access
    Replies: 1
    Last Post: 05-13-2010, 05:11 AM
  3. newbie-real NOVICE
    By SHCC in forum Database Design
    Replies: 1
    Last Post: 02-09-2010, 03:42 AM
  4. Real time database question
    By joet5402 in forum Forms
    Replies: 7
    Last Post: 04-01-2009, 09:00 PM
  5. Update a combo box in real time
    By protean_being in forum Forms
    Replies: 0
    Last Post: 05-17-2008, 07:39 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums