Include username and name from Windows into textbox (1 Viewer)

charly.csh

New member
Local time
Yesterday, 23:10
Joined
May 7, 2020
Messages
9
Hi everyone,

I am making a form as report and also want to include the creator of the report based on the "windows user name and also the name" by default in the Windows system
The username is not an issue but I don't know how to add the "name by default" from the computer registration. Does somebody know the option?

Dim wshNetwork As Object 'New wshNetwork
Set wshNetwork = CreateObject("WScript.Network")
Me.Issuerusername = wshNetwork.username
'Me.IssuerName = wshNetwork. ???
Set wshNetwork = Nothing

'username: charlycsh
'Name: "Charles M. Burns"
 

Isaac

Lifelong Learner
Local time
Yesterday, 21:10
Joined
Mar 14, 2017
Messages
8,778
What I have always done is maintain a strict table of any and all database users with all the required info … Just a thought..
 

charly.csh

New member
Local time
Yesterday, 23:10
Joined
May 7, 2020
Messages
9
It is a good idea, June7 also recommended to me the usage of Dlookup.

The idea of this was more like avoid that somebody else issue a report in the name of other person, at least the "issuer" will be recorded with the windows user but sometimes is name is something like "qasxd" and it does not give you more info
 

Isaac

Lifelong Learner
Local time
Yesterday, 21:10
Joined
Mar 14, 2017
Messages
8,778
Yes, if you have potentially multiple users using the same database login with different pc's and different network logins, I can see what you mean.
 

smig

Registered User.
Local time
Today, 07:10
Joined
Nov 25, 2009
Messages
2,209
This might help you

Code:
Public Sub pbListAllEnvironVars()
  
Dim i As Long

For i = 1 To 255
    If IsNull(Environ$(i)) = False Then
        Debug.Print i & "  -  " & Environ$(i)
    End If
Next i

End Sub
 

isladogs

MVP / VIP
Local time
Today, 05:10
Joined
Jan 14, 2017
Messages
18,246
There are only about 40 Environ variables so I would suggest modifying the code suggested by @smig accordingly

Dim I As Integer
For I =1 To 40 ….

The code as written does not prevent blank rows appearing for i=41 to 255
 

Isaac

Lifelong Learner
Local time
Yesterday, 21:10
Joined
Mar 14, 2017
Messages
8,778
Surely lan email address won't be an environment variable anyway, unless the local IT dept has done some major corporate IT ninja woofoo
 

June7

AWF VIP
Local time
Yesterday, 20:10
Joined
Mar 9, 2014
Messages
5,486
I got 48 variables. Returns nothing after that. See the cross post link in post 3.
 

Isaac

Lifelong Learner
Local time
Yesterday, 21:10
Joined
Mar 14, 2017
Messages
8,778
Since you can create environment user account variables, some may have more than others..?
 

June7

AWF VIP
Local time
Yesterday, 20:10
Joined
Mar 9, 2014
Messages
5,486
Not sure what you mean about creating environment user account variables. I am just talking about intrinsic parameters for the Environ() function.
 

Isaac

Lifelong Learner
Local time
Yesterday, 21:10
Joined
Mar 14, 2017
Messages
8,778
I don't know about creating environment user account variables. I am just talking about intrinsic parameters for the Environ() function
That code will loop through all environment variables. Although I am not sure whether they include system only, or system + user.
 

June7

AWF VIP
Local time
Yesterday, 20:10
Joined
Mar 9, 2014
Messages
5,486
All I can say is after 48, returns nothing.

IsNull() test is not working. Prints anyway. Check for empty string instead.
 

smig

Registered User.
Local time
Today, 07:10
Joined
Nov 25, 2009
Messages
2,209
There are only about 40 Environ variables so I would suggest modifying the code suggested by @smig accordingly

Dim I As Integer
For I =1 To 40 ….

The code as written does not prevent blank rows appearing for i=41 to 255
You are right.
Look carefully at my code
It wont print blank values
 

June7

AWF VIP
Local time
Yesterday, 20:10
Joined
Mar 9, 2014
Messages
5,486
I ran your code and 255 lines output. I could see only 57 - 255 because the others rolled off screen.
 

isladogs

MVP / VIP
Local time
Today, 05:10
Joined
Jan 14, 2017
Messages
18,246
It does print blanks which is why I commented on it
1590126137167.png

...and so on

However this version doesn't print any blank lines

Code:
Public Sub pbListAllEnvironVars()
 
Dim i As Integer

For i = 1 To 255
    If Nz(Environ(i), "") <> "" Then
        Debug.Print i & "  -  " & Environ(i)
    End If
Next i

End Sub
 

Users who are viewing this thread

Top Bottom