Lookup User Full Name based on Login Name (1 Viewer)

Steve@trop

Registered User.
Local time
Yesterday, 23:59
Joined
May 10, 2013
Messages
148
I've hit one more snag with this. When network connectivity is lost, the runtime crashes with a runtime error. Even when the database is run locally. I think it is because it is doing an Active Directory search. I'm wondering if there is a workaround for this that you can think of. I'd be willing to have some records without the users name in them. Is there a way to have it ignore the error and just leave the textbox blank when it can't get the info from AD?

Thanks,

Steve
 

Steve@trop

Registered User.
Local time
Yesterday, 23:59
Joined
May 10, 2013
Messages
148
I found my own answer. I just had to include some error handling code.
Code:
On Error Resume Next
just before the AD lookup and then
Code:
On Error GoTo 0
after it. It works perfectly so far.

Steve
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 16:59
Joined
Jan 20, 2009
Messages
12,853
On Error Resume Next is more of Error ignoring than Handling.

I would suggest putting On Error Goto ErrorHandler in the usual style of Access error handlers.

At ErrorHandler just exit the function. The string that is returned will still be empty so that is what will be displayed.

Alternativey you can choose to return some appropriate string. With some logic this could be adjusted to return a messge about connectivity problems or "User Not Found" .

I will have a look at adding this sometime in the next couple of days.
 

Steve@trop

Registered User.
Local time
Yesterday, 23:59
Joined
May 10, 2013
Messages
148
You are absolutely correct, it is more Error ignoring than handling. In this case, it's probably ok though. What I plan to do is make that field a required field so that in cases where it doesn't get populated by the code when it errors out, they can manually enter the data. This way, the code won't crash the program and they'll be able to continue working.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 16:59
Joined
Jan 20, 2009
Messages
12,853
Obviously if the machine is off the network then they can't do the LDAP query. The advantage of a local table is that you can always get the name.

It seems you should be storing the login and translating it only for reporting which presumably is done while on the domain.
 

TerribadCoder

Registered User.
Local time
Yesterday, 23:59
Joined
Mar 8, 2014
Messages
20
The code is easily modified to return other attributes by changing the fields returned by the command and the assignment to the returned string.

However, Active Directory holds some attributes such as Group memberships as multivalue fields. This adds further complexity to to the task. I have the code to return group memberships too if anyone is interested but I would like to tidy it up and test it before posting.

Hate to revive an old thread, but this post provided me with a solution to a question, so thank you! Now I'm pulling in the manager field from AD hoping it would display just the manager name, but am getting a bunch of extra fields. I think this is what you were speaking of when referring to a multivalue field. Is there any way to pull just the first and last name of the manager? Thanks a bunch!
 

Coxylaad

New member
Local time
Today, 07:59
Joined
Jan 11, 2022
Messages
21
However, Active Directory holds some attributes such as Group memberships as multivalue fields. This adds further complexity to to the task. I have the code to return group memberships too if anyone is interested but I would like to tidy it up and test it before posting.
Hi - first post here, apologies if I am jumping in at the wrong place, but the above is exactly what I am trying to do. I need to pull out the group memberships for the current user when on start up and record the values. I am going to use them as a basic permissions system. Do you have an example of how to do it available?
 

NauticalGent

Ignore List Poster Boy
Local time
Today, 02:59
Joined
Apr 27, 2015
Messages
6,359
Do you have an example of how to do it available?
I see no one has responded to your question so I am givning it a bump. Old threads tend to get ignored so it is probably best to start a new thread, referencing this thread specifically post #13 and maybe even tagging Galaxiom since it is his code you are seeking.

Welcome to AWF BTW!
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 16:59
Joined
Jan 20, 2009
Messages
12,853
Sorry I have not responded. I don't even have Access at home to experiment on now, let alone a domain and I am way too busy at work most of the time.

These days I query our Active Directory via MS SQL Server using an ADSI Linked Server. It is far, far simpler than using VBA which is using complex code to do what SQL Server can support with simple queries. Any database developer on a domain should definitely start using SQL Server, especially if they are trying to set up user permissions.

Access developers who have not gotten into SQL Server as the back end have no idea what an incredible resource they are missing out on and how hard they are making their job by not using it. Access is a great rapid development tool for front ends but it is incredibly limited as a back end.
 

isladogs

MVP / VIP
Local time
Today, 07:59
Joined
Jan 14, 2017
Messages
18,246
Here is a different approach which I use to get the current user's full name in a single function
For more info, see https://msdn.microsoft.com/en-us/library/aa394221(v=vs.85).aspx

Rich (BB code):
' This function returns the full name of the currently logged-in user
Public Function GetUserFullName() As String
    Dim objWin32NLP As Object, objItem As Object
    On Error Resume Next
    ' Win32_NetworkLoginProfile class  https://msdn.microsoft.com/en-us/library/aa394221%28v=vs.85%29.aspx
    Set objWin32NLP = GetObject("WinMgmts:").instancesof("Win32_NetworkLoginProfile")
    If Err.Number <> 0 Then
        MsgBox "Unable to retrieve current user name" & _
            "WMI is not installed", vbExclamation, "Windows Management Instrumentation"
        Exit Function
    End If
    For Each objItem In objWin32NLP
       If objItem.Flags > 0 Then GetUserFullName = objItem.FullName
    Next
End Function
 
Last edited:

NauticalGent

Ignore List Poster Boy
Local time
Today, 02:59
Joined
Apr 27, 2015
Messages
6,359
I don't even have Access at home to experiment on now, let alone a domain and I am way too busy at work most of the time.
You absence has not gone unnoticed and your valuable contributions are missed.
 

Users who are viewing this thread

Top Bottom