Getusername function

tucker61

Registered User.
Local time
Today, 01:45
Joined
Jan 13, 2008
Messages
337
I have a function called hetusername, which looks at who is logged on, to see if they have permissions to press certain buttons etc.

What this means is that a user could be logged on for 1 hour and in that time the code could check their user details 10 or more times.

Trying to think of a way that it inly needs to check the username once, and this is stored somewhere.

I do have a hidden timer form. So might be best just storing the data on that hidden form.

Any thoughts ?
 
I used to ask people to log in, and stored it in a TempVar.
 
I also use a login form that validates the ID when the user opens the database. If the user is valid, the login form hides itself but stays open and opens the menu. Thereafter, the code uses the bound data on the login form to check authorizations.
 
Even if you don't use a login form, you could probably use the getusername function once to store the username in a tempvar and then simply refer to that tempvar whenever you need that information rather than execute the function multiple times. Just a thought...
 
If you want to lock certain buttons inside the form, you can use (InputBoxDK) which is enough for that. I use it in most programs.
Code:
Private Sub Option8_BeforeUpdate(Cancel As Integer)

If Me.Option8 Then
    Me.Button name.Enabled = False
ElseIf InputBoxDK("Enter the password to unblock the print buttons.", "access-programmers.co.uk") = "pass" Then
    Me.Button name.Enabled = True
MsgBox " The ban has been lifted.", , "AZ"
Else
    MsgBox "Incorrect password", , "AZ"
    Cancel = True
End If

End Sub
 
If trying to set as Temp Vars.
Is the following correct - as i need to remove the first and last character from the username (as within AWS).

Code:
TempVars!MyTempVar = Mid(Environ("UserName"), 2, Len(Environ("UserName")) - 2) ' Create or set the TempVar

My Original code is below
Code:
Public Function GetUserName() As String
GetUserName = Mid(Environ("UserName"), 2, Len(Environ("UserName")) - 2)
End Function
 
Debug.Print it and find out?
Might want to give it a better name as well? TempVars!Username ?
 
And just where do you find InputBoxDK ?
Code written by Daniel Klann
March 2003
64-bit modifications developed by Alexey Tseluiko and Ryan Wells (wellsr.com) February 2019

234.PNG
 
Debug.Print it and find out?
Might want to give it a better name as well? TempVars!Username ?
Compile Error - Invalid outside procedure - Highlighting the "Username" in Mid(Environ("UserName")
 
Works for me in immediate window?
1728676001895.png
 
Even if you don't use a login form, you could probably use the getusername function once to store the username in a tempvar and then simply refer to that tempvar whenever you need that information rather than execute the function multiple times. Just a thought...
If you don't use a login form, you will have trouble testing because you will need to find a way for "getusername" to return the ID you want to test with.
 
If you don't use a login form, you will have trouble testing because you will need to find a way for "getusername" to return the ID you want to test with.
I inherited an app with a login form for the users to enter their username and password, and I decided to use GetUsername instead. I never had any problems with returning the ID, and the users were happy for not having to remember one more password.
 
Last edited:
I inherited an app with a login form for the users to enter their username and password, and I decided to use GetUsername instead. I never had any problems with returning the ID, and the users were happy for not having to remember one more password.
I think you missed my point. Also, they can use whatever password they like. Assuming the login eliminates 50% of the user verification AND allows a random person to sit down at your desk as you.
 

Users who are viewing this thread

Back
Top Bottom