Results 1 to 7 of 7
  1. #1
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162

    Populate module info into a form (LDAP Attributes)

    Hi,



    Im struggling with populating attributes onto a textbox in a form, Ive code my code below:

    Code:
    Public Function AdUserInfo() As String
    
    Dim sysInfo As ADSystemInfo
    Dim oUser As ActiveDs.IADsUser
    Dim LName As String, FName As String
    Dim UserDepartment As String
    Set sysInfo = CreateObject("ADSystemInfo")
    Set oUser = GetObject("LDAP://" & sysInfo.UserName & "")
    'Debug.Print oUser.EmailAddress
    'Debug.Print oUser.Division
    UserDepartment = oUser.Division
    Set sysInfo = Nothing
    Set oUser = Nothing
    
    End Function
    If I uncomment the debug.print it shows what Im expecting to see but how do I then output that to a textbox?

    Thanks

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    textBox1= oUser.Division

  3. #3
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Quote Originally Posted by ranman256 View Post
    textBox1= oUser.Division
    Ideal, but I don't think Im doing it correctly. If I create a public function as per the one detailed above, the only way I can see how to populate a textbox on a form is to assign

    Forms!TimesheetForm.Department_txtbx = oUser.Division

    on the module and then call the module when I open the form - which works fine.

    But am I not correct in thinking I should be able to assign the result to any form I like without having to call it? I thought that was the idea of a public function? And thanks for your help Im trying to grasp a bit of how the code works all my own work though

  4. #4
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    where is your function, in a Standard Module? If so, you can have your function return a value or you can store the values in public variables. Another option would be to use the function within the form's module.

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,525
    Then the routine should be in the form, not the module.

  6. #6
    shabbaranks is offline Competent Performer
    Windows 7 32bit Access 2007
    Join Date
    Oct 2011
    Posts
    162
    Quote Originally Posted by ItsMe View Post
    where is your function, in a Standard Module? If so, you can have your function return a value or you can store the values in public variables. Another option would be to use the function within the form's module.
    Although my function returns multiple values and I only want one, (my theory behind this was I could call different aspects of the function as and when required) is it best practice to create a function to return only one value? Or consolidate the out put to one value?

  7. #7
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2013
    Posts
    7,862
    A cheap and easy way would be to use global variables in a standard module. One thing to consider is that all declarations in a Standard Module will use memory as soon as your application starts. So, the proper way might be to create a custom, stand alone, class. For a function in a Standard Module maybe ...

    Code:
    Public gstrFullName As String
    Public gstrFirstName As String
    
    Public Function fAdUserInfo() As Boolean
    
    Dim sysInfo As New ADSystemInfo
    Dim varUserName As Variant
    
    gstrFirstName = "" 'Default
    gstrFullName = "" 'Default
    fAdUserInfo = False 'Default
    varUserName = sysInfo.UserName
    
        If varUserName > "" Then
            
            Dim oUser As ActiveDs.IADsUser
            Set oUser = GetObject("LDAP://" & varUserName & "")
            fAdUserInfo = True
            gstrFirstName = oUser.FirstName
            gstrFullName = oUser.FullName
            
        Else
        
            MsgBox "There was a problem. Unable to continue."
            
        End If
    
    End Function
    And then you could have a sub-procedure in a form

    Code:
    Private Sub Command0_Click()
    
        If fAdUserInfo = True Then
        
            Debug.Print gstrFullName
            Debug.Print gstrFirstName
            
        End If
    
    End Sub

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

Similar Threads

  1. Replies: 13
    Last Post: 05-07-2014, 11:35 AM
  2. Populate a table with info from a form
    By JudyK in forum Forms
    Replies: 13
    Last Post: 02-08-2012, 07:32 PM
  3. LDAP query
    By croydon in forum Programming
    Replies: 3
    Last Post: 07-23-2011, 10:43 AM
  4. Replies: 4
    Last Post: 05-16-2011, 04:58 PM
  5. How to populate info???
    By Access Newbie in forum Access
    Replies: 2
    Last Post: 08-18-2010, 08:51 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