• Home
  • Demo
  • Code
  • About
  • Contact

Code Snippets

In all the times I have spent participating in forum discussions about all sorts of users' questions, I have learnt a great deal from all the participants.

I have decided to post some of the sample codes that I found users were asking for almost all the time to help me keep them in one place and to make it easier for me to share them again and again.

Hope you find them useful.

 Get User's E-mail Address from Active Directory

Get User's E-mail Address from Active Directory

This was something I originally posted on LinkedIn. It retrieves the network user's e-mail address from Active Directory. If no username was passed as argument, the function will retrieve the e-mail address of the currently logged in user.

Public Function GetUserEmail(Optional strCN As String) As String
'Retrieve user's email address from Active Directory
'Source: http://accessmvp.com/thedbguy

On Error GoTo errHandler

Dim objADInfo As Object
Dim objADUser As Object
Dim strArray() As String

Set objADInfo = CreateObject("ADSystemInfo")

If strCN > "" Then
    strArray = Split(objADInfo.UserName, ",")
    strArray(0) = "CN=" & strCN
    Set objADUser = GetObject("LDAP://" & Join(strArray, ","))
Else
    Set objADUser = GetObject("LDAP://" & objADInfo.UserName)
End If

GetUserEmail = objADUser.Mail

errExit:
    Set objADUser = Nothing
    Set objADInfo = Nothing
    Exit Function
    
errHandler:
    MsgBox Err.Number & ": " & Err.Description
    Resume errExit

End Function

 

Home | Demo | Code | About | Contact

 

Contents

  • Generate GUIDs
  • Backup and Compact BE
  • Get E-mail Address from AD
  • Get Network Username
  • Leigh's Generic Recordset
  • Trim Inner Spaces
  • Get Subform Control Name
  • The Opposite of DSum()
  • Concatenate Records
  • Get Network Domain Name
  • Get Computer Name
  • Get BE Info
  • Execute Action Queries
  • Extract Email Address

 

Copyright © 2012-2019, theDBguy™. All Right Reserved.
✉ theDBguy@gmail.com