Results 1 to 6 of 6
  1. #1
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56

    Populate Form Field With Value from Function

    I want to populate the employee_seq field on my form fwith the value returned by the following function.



    If I tie the function to an unbound form field it works fine. I need it to be tied to the bound field "employee_seq".

    Code:
    Function GetUserFullName() As String
    
        Dim WSHnet As Object
        Dim UserName As String
        Dim TheUser As Object
        Dim UserDomain As String
        Dim UserFullName As String
        Dim fName As String
        Dim Lname As String
       
        Set WSHnet = CreateObject("WScript.Network")
        UserName = WSHnet.UserName
        UserDomain = WSHnet.UserDomain
        Set TheUser = GetObject("WinNT://" & UserDomain & "/" & UserName & ",user")
        UserFullName = TheUser.FullName
      '  GetUserFullName = UserFullName
        Lname = Left(UserFullName, InStr(UserFullName, ",") - 1)
        fName = Mid(UserFullName, InStr(UserFullName, ",") + 2)
        GetUserFullName = fName & " " & Lname
       
    End Function
    Attached Thumbnails Attached Thumbnails Form2.JPG  

  2. #2
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I would use some VBA behind the Form. Maybe something like ...
    Me.emplyee_seq.Value = GetUserFullName

  3. #3
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    I tried exactly that and it did not work.

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    It didn't? What happened? How do you know it did not work?

    You can test the function via the immediate window (Ctrl + G). Paste the following into the immediate window and hit Enter
    ?GetUserFullName

  5. #5
    gammaman is offline Advanced Beginner
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2013
    Posts
    56
    When I run in the immediate window, it does nothing. However as stated before, when I tie the function to an unbound form field, the function correctly displays the user logged into windows.

  6. #6
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    Quote Originally Posted by gammaman View Post
    When I run in the immediate window, it does nothing...
    In order for a function to be available globally throughout the app, it needs to be placed within a Standard Module. Of course, there are exceptions. However, that is the basic way to implement a Public Function.

    Place you function in a Standard Module for it to be available from multiple forms and or reports.

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

Similar Threads

  1. Replies: 1
    Last Post: 09-16-2014, 12:32 PM
  2. Populate one form field based on another
    By jhrBanker in forum Forms
    Replies: 6
    Last Post: 06-01-2013, 09:28 AM
  3. Replies: 3
    Last Post: 10-03-2011, 02:33 PM
  4. Auto populate a field (without a form)
    By DonL in forum Access
    Replies: 1
    Last Post: 06-21-2011, 03:19 AM
  5. Replies: 2
    Last Post: 05-22-2009, 01:07 PM

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