Results 1 to 4 of 4
  1. #1
    pfales is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    23

    Post Auto fill Txtbox with logged in Users Name

    I do not know if this has been asked previously or not if it has I apologize for the repeat.
    I am creating an access application that will be utilized by multiple users. I have managed to be able to get the Widows UserID of the individual that is logged on to show in the forms. What I am trying to do now is change it so that in stead of the UserID the full UserName appears in the txtbox. Here is the script I am using:

    Public Function fnGetUserID()
    Dim User As String * 50
    Dim UserID As String
    Dim UserName As String
    Dim Trash As Long
    Dim intCnt As Integer
    Dim db As Database
    Dim rst As Recordset
    Set db = CurrentDb()
    Set rst = db.OpenRecordset("tblAccounts", dbOpenDynaset)
    ' UserID = InputBox("Enter UserID", "LAN Admin User ID")
    'get username
    Trash = GetUserName(User, 20)
    fnGetUserID = UCase(Left(User, InStr(User, Chr(0)) - 1))
    'fnGetUserID = Trim(UCase(Left(User, 20 - 1)))

    'Password = InputBox("Enter Password", "LAN Admin User ID Password")
    rst.FindFirst "(UserID='" & UserID & "' AND UserName= '" & UserName & "')"
    'rst.FindFirst "(UserID='" & UserID & "')"
    'rst.FindNext "(UserName='" & UserName & "')"
    If rst.NoMatch = False Then
    MsgBox ("Sorry NO records found")
    DoCmd.Close
    'Security = "X"
    Else
    With rst
    UserName = Trim(!UserName)
    End With


    End If

    End Function

    This script with run and when it gets to, " UserName = Trim(!UserName)" it will actually show the correct full UserName however, when the Function completes it still inserts the UserID into the txtbox. Ant assistance would be greatly appreciated, and if you could explain what I have wrong I would really be gratefull.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    49,950
    You declare variables, User, UserID, UserName but I don't see them being set before they are used.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    pfales is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Apr 2013
    Posts
    23

    Smile

    Quote Originally Posted by June7 View Post
    You declare variables, User, UserID, UserName but I don't see them being set before they are used.
    Thank you I will take care of that, I did not notice that.

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    49,950
    Is this function called from textbox?

    The function is returning value of: UCase(Left(User, InStr(User, Chr(0)) - 1))

    Setting value of field in the recordset will not affect the display of already open form until the form's RecordSource is requeried or refreshed unless the recordset is a clone of the form's RecordSource.

    If you want the function to set value of a different textbox then either change the value returned and call it from that textbox or set textbox value by code with:

    Me.textboxname = UserName

    instead of populating the recordset with:
    UserName = Trim(!UserName)
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

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

Similar Threads

  1. Auto fill
    By jojomac in forum Access
    Replies: 1
    Last Post: 10-10-2012, 09:57 AM
  2. Auto Fill
    By Scotty J in forum Forms
    Replies: 10
    Last Post: 11-21-2011, 10:08 AM
  3. Auto-fill
    By sidewayzalex in forum Database Design
    Replies: 49
    Last Post: 09-14-2011, 11:12 AM
  4. Auto Fill
    By Kerrydunk in forum Forms
    Replies: 16
    Last Post: 04-26-2011, 12:15 AM
  5. Auto-Fill
    By sophiecormier in forum Programming
    Replies: 3
    Last Post: 10-02-2010, 08:29 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 - Senior Forums