How does SharePoint know who I Am? Does Access? (1 Viewer)

aaronb50

Registered User.
Local time
Yesterday, 21:28
Joined
Mar 2, 2014
Messages
185
How does Outlook know who I Am? Does Access?

I have a login page for all my Access programs. They works just fine and so far no issues.
But I was thinking yesterday that when I log onto my company computer, somehow Outlook knows who I am from that login. That is leading me to believe that somehow Office Suite is talking to something on my computer and knows who I am and can access my information.
How is this done? And can I create Access programs that can also access this information so I can get rid of my login pages?
 
Last edited:

GinaWhipp

AWF VIP
Local time
Today, 00:28
Joined
Jun 21, 2011
Messages
5,899
The reason Outlook knows who you are is that is the way IT set it up via your Network Log on. Quite a few Companies do it that way. As for your other Office programs, they do not require a *log on* to be used. That said, Office 2013 wants you to log on but you can work offline.

I don't know what other information you are referring to that you think your Office programs can access but they can't *access* anything unless you open it within the program, such as, opening a Word document... only then can Word *see* it.

All that said, if you are required to log on to your Access programs then depending on which version you are using will depend on the answer how it can be done. I have done this by capturing the Users Network ID and using that to determine which Forms they have access to and what information they can see. This should get you started...

http://www.access-diva.com/f7.html

More links can be found at the bottom of the page.
 

aaronb50

Registered User.
Local time
Yesterday, 21:28
Joined
Mar 2, 2014
Messages
185
The Users Network ID. That sounds like what I’m looking for.
So right now when someone opens one of my programs they have to login with a user name and password that is stored on an Access table in the back end of the program. That’s how I am controlling who has access to what.
Is it possible to skip that step by having Access automatically pull their Network ID once they open the program?

I would set up the on load procedure to reach out and get that ID and then I could use that to find who the user is on that back end table.

On Load:

Some Variable = User Network ID
.Movefirst
.FindFirst “[NetworkID] = “”” & Some Variable & “”””

I just need the correct syntax to get and set that user Network ID
I can’t download that code sample at work. I’ll look at it tonight and see if it shows me how to get that Network ID
 

aaronb50

Registered User.
Local time
Yesterday, 21:28
Joined
Mar 2, 2014
Messages
185
Oh, and I’m going to need to know everyone’s Network ID so I can place it with their record on the backend so it can be found later. How do I figure out what my Network ID is?
 

Rx_

Nothing In Moderation
Local time
Yesterday, 22:28
Joined
Oct 22, 2009
Messages
2,803
The Environ is one way to check usernames. Its not perfect, but very useful.
My application runs in a sandbox called Citrix, so it is good enough.
I have a table called tbl_Users
It has the users LAN ID in one column.
In other columns it has an "A" or "I" for Active and Inactive.
In this example a field named Regulatory has A/I.
This looks up the Lan ID, does the person have an account, and determines if there is an A/I in Regulatory. If A, then allow the Regulatory Wells button to be clicked.

Did that help?

Code:
Private Sub btn_Wells_Click()
Dim UserLogin As String
Dim MyTablename As String
Dim MyField2Match As String
Dim NodeIDValue As Variant
10        On Error Resume Next
20          UserLogin = Trim(Environ("username"))
30          MyTablename = "tbl_Users"                 ' name of table to lookup the value for match
40          MyField2Match = "Regulatory"
50          NodeIDValue = DLookup(MyField2Match, MyTablename, "[User_ID] = '" & UserLogin & "'")         '& intPrimaryKeyID)
                ' example of using number with blank If DLookup("AllowPermitStartDt", "Ed_SwType", "Ed_IDSWType =" & Nz(Me.SW_Type, 0)) = "A" Then
60        If NodeIDValue = "A" Then
            ' The line above checks the tbl_User Table Regulatory field. An "A" for that user it opens Regulatory
            ' once ED main form is ready, un-comment this code and add the name.
70          If fIsLoaded("ED_Home_2") = True Then ' What ever ED main form is called
80              MsgBox "Please Close the Regulatory Wells Window before starting Environmental", vbOKOnly, "One DB at a time Rule"
90          Else
100                DoCmd.OpenForm "Home_2"
110         End If
120       Else
        ' An "I" or blank for that user will not open the form.
            MsgBox "This User does not have rights to Regulatory. Please ask supervisor to add or change tbl_Users - Regulatory column", vbOKOnly, "User Rights Prevent Regulatory from opening"
130             Exit Sub
140       End If
        
    'DoCmd.OpenForm "Home_2"
150   Exit Sub


End Sub
Or, if you want to just log users and some other interesting information then put this in the click event of a button or opening of a form.
Code:
'---------------------------------------------------------------------------------------
'  Create table named tLogUsage2
'  Add field (date/ time) UseDate, strFormName, CallingProc, Username, ControlName
'  use: in code, typically at command buttons or other key areas, add code to log
'   the name of the form, the calling procedure, and the control name
'   in no time, there will be users stats to show what parts the users like the most in your application
'    Example:  Call LogUsage("frmMainSwitchboard", "cmdOpenReport_click", "cmdOpenReport")
Function LogUsage2(ByVal strFormName As String, _
    strCallingProc As String, Optional DelayTime) As Boolean
10       On Error GoTo Err_LogUsage2
          Dim Rst As DAO.Recordset  ' The tLogUsage table
20            Set Rst = CurrentDb.OpenRecordset("tLogUsage2", 2, dbAppendOnly + dbSeeChanges)
30            Rst.AddNew
40                Rst![UseDate] = Now()
50                Rst![strFormName] = strFormName
60                Rst![CallingProc] = strCallingProc
70                Rst![UserName] = Environ("username")
80                If Not IsMissing(DelayTime) Then
90                    Rst![DelayTime] = Left(DelayTime, 75)
100               End If
110           Rst.Update
120           Rst.Close
130           LogUsage2 = True

Exit_LogUsage2:
140       Set Rst = Nothing
150       Exit Function

Err_LogUsage2:
          ' just resume next and the usage is not logged
  'MsgBox Err.Number & Err.Description
160       Err.Clear
170       Resume Exit_LogUsage2
End Function
 
Last edited:

aaronb50

Registered User.
Local time
Yesterday, 21:28
Joined
Mar 2, 2014
Messages
185
"UserLogin = Trim(Environ("username"))" looked like what I was looking for.

I ran a quick program:

Private Sub Form_Load()

Dim UserLogin As String

UserLogin = Trim(Environ("username"))

MsgBox "" & UserLogin & ""

End Sub

And sure enough my computer login name showed up. That’s exactly what I was looking for.

Thank you so much!!! Now I'm going to go back and get rid of the login page on all my programs.

So I always like to learn what code is doing when I copy it. What is Trim(Environ doing exactly? Where is it pulling the username from?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:28
Joined
Feb 28, 2001
Messages
27,186
The key here is that if your network people have set up your workstation for you with domain-class security, they very likely set it up to put your domain-based username in the so-called environmental variable area on your machine. Depending on just how tightly your system is set up, you might be able to grab this data via Environ. I not only get the user ID, I also get the Machine ID. Then, if you have problems with users who won't get out of the database when you need exclusive access, you can read the .LDB file with Notepad or IE and see the machine ID of the users currently in the database. Then, if you conveniently had a copy of this table handy, you would know what people to call to get your exclusive access.

Trim$ just removes leading and trailing spaces from whatever is inside the parentheses.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:28
Joined
Jan 20, 2009
Messages
12,852
I have expressed my distaste for Environ("Username") many times so I won't go over that again. You can search the forum my username and that term if you care to see why it is a very poor choice especially when the are better alternatives.

Another way to manage user permissions on a domain is through the use of LDAP queries. This can retreive any of the public Active Directory information about any user.

Users can be placed in an AD group. The LDAP query determines if they are a member of that group and assigns permissions in your app accordingly.
 

aaronb50

Registered User.
Local time
Yesterday, 21:28
Joined
Mar 2, 2014
Messages
185
Thanks for the explanation Doc. So is this where .pdf gets its data for its digital signatures?

I was having a big issue with people never logging out of the programs. At times I would have to change the name just so I could make a quick fix and let others use it while I tracked down who was on it. It got old real fast!!

So on the users table I added a Logged in true or false field and then created a hidden form that runs in the background of all my programs that is on a timer event. When the user logs in, their logged in field is set to true. Then every 4 minutes that timer event checks that field to see if the field is still true. Any time I need to kick everyone out of a program, I just go down the logged in field and mark everyone as false. Then when their timer event sees that field as false, it exits the program.

Works perfect every time!!!

Galaxiom, I’m making all this up as I go along so I’m always open for a better way. I’m loving this Environ("Username") in lieu of a login page but if there is an even better way I’m in.

As I was searching to figure out just what Environ("Username") was doing I came across some code that used LDAP to get the actual name of the user and not just their user name. That had me thinking that like Doc said, there are a set of variables being set somewhere when I log onto my computer that can be accessed.

Is LDAP the way to get that info?

This is a simplified version of the code I found that gets the users name.

Private Sub Form_Load()

Set objInfo = CreateObject("ADSystemInfo")
strLDAP = objInfo.UserName

strName = ""
Set objUser = GetObject("LDAP://" & strLDAP)

strName = objUser.Get("givenName") & Chr(32) & objUser.Get("sn")

MsgBox "" & strName & ""

End Sub



I’m guessing
strLDAP = objInfo.UserName

is designating exactly what type of info to go out and grab. So if I had a list of the other data that is available and what word was used to get it, I could just replace .UserName in that string with whatever word was needed to pull the data I wanted.
Where can I find a list of those variables that get set and what words I need to use to get to them?
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 23:28
Joined
Feb 28, 2001
Messages
27,186
There are other ways to do Environ("Username") and I understand that Galaxiom is not a fan of the method. It happens that it works in my context, but as I said, it depends on who set up the environment and how they went about it.

Look at Galaxiom's alternatives just to see another viewpoint. I can do an LDAP query but in my case the network is so slow that I need something that doesn't depend on yet another network call. Environ("Username") depends on something already done on the machine, but I want to make it clear that my environment might be special enough to make this method work for me but not for Galaxiom.
 

Galaxiom

Super Moderator
Staff member
Local time
Today, 14:28
Joined
Jan 20, 2009
Messages
12,852
I mentioned the the LDAP query as a centralised way to store and retrieve information about the user across a domain, not as an alternative to finding the username itself.

Environment variables can be easily changed which is why they are an insecure way to identify the user. It bewilders me why so many continue to promote it when better alternatives are available.

The following code returns the actual username from Windows.
Code:
CreateObject("wscript.network").UserName
 

Users who are viewing this thread

Top Bottom