GetUserID

hfsitumo2001

Member
Local time
Yesterday, 16:04
Joined
Jan 17, 2021
Messages
394
Can anyone give me the sample of the module/VBA for "GetUserID"?
 
Which user ID are you trying to get? Is that the same as the network login or Username?
 
You can use Environ("Username") if you like
 
Which user ID are you trying to get? Is that the same as the network login or Username?
I have the public fuction like this:
Code:
Function GetAccessTypeHfs()

GetAccessTypeHfs = DLookup("AccessType", "LoginTable", "AutoID =" & GetUserID & "")

End Function
and in my on load form is this:
Code:
Private Sub Form_Load()

If GetAccessTypeHfs = "Admin" Then
Me.ItemCode.Locked = False
Else
MsgBox "Only Admin can edit itemcode", vbInformation, "Frank's Warning"
End If
End Sub
When I debug, it hang in the "GetUserID", it seems I need to have the function called.
GetuserID.jpg
 
Change GetUserID to environ("username")
 
Change GetUserID to environ("username")
Hi Isaac, are you saying I need to change the module to read like this?:
etAccessTypeHfs = DLookup("AccessType", "LoginTable", "AutoID =" & environ("username") & "")
 
In fact you might need single quotes, too. I assume AutoID is a text field ...right?

If so, change to:

etAccessTypeHfs = DLookup("AccessType", "LoginTable", "AutoID ='" & environ("username") & "'")

(copy/paste directly - note i added some single quotes in there)
 
In fact you might need single quotes, too. I assume AutoID is a text field ...right?

If so, change to:

etAccessTypeHfs = DLookup("AccessType", "LoginTable", "AutoID ='" & environ("username") & "'")

(copy/paste directly - note i added some single quotes in there)
No AutoID is an AutoNumber, that is the primary key in my log in table, Accesstype is the short text type
 
Then why are you looking it up by ID in the first place? To answer your question, wherever you are using GetUserID, substitute Environ("username")

But based on what you are saying now, you aren't using GetUserID in any place it makes sense to.
I think your GetAccessTypeHfs is totally wrong..
 
Then why are you looking it up by ID in the first place? To answer your question, wherever you are using GetUserID, substitute Environ("username")

But based on what you are saying now, you aren't using GetUserID in any place it makes sense to.
I think your GetAccessTypeHfs is totally wrong..
ut based on what you are saying now, you aren't using GetUserID in any place it makes sense to.
So What is the third part of the statement usually, I just followed what is told by our community is other forum.
So can I make it like this? GetAccessTypeHfs = DLookup("AccessType", "LoginTable", AutoID = 1 , because UserID which name is Auto ID for "Admin" is 1 ( number)
 
Usually when people want GetUserID, it's either a module with a windows API (which gets the logged-in username), or it's Environ("username") (which also, similarly, gets the logged-in username).

It sounds like you have a second question now which is totally different - I suggest posting a new thread. Sorry, I can't understand what you're trying to do now with the Admin and the 1
 
Usually when people want GetUserID, it's either a module with a windows API (which gets the logged-in username), or it's Environ("username") (which also, similarly, gets the logged-in username).

It sounds like you have a second question now which is totally different - I suggest posting a new thread. Sorry, I can't understand what you're trying to do now with the Admin and the 1
if you look at on load of the form code, that is the criteria to be able for the Admin to edit the item code, other access type can not. And the USERID for Admin is 1
as you can see below, this is my login table:
logitable.jpg
 
Isaac, if I open the form, the error message is compile error, mismatch type see below:

mismatched.jpg
 
i think it GetUserID is related to your Login Form.
see this demo.
 

Attachments

i think it GetUserID is related to your Login Form.
see this demo.
What is the password Arnel. To be honest, I am not expert in all of this, I just watched on Youtube and I follow step by step, so my login system is still very simple one. As I already shew that my table fields just consist of , UserID, Name, password, and Accesstype. So I need to study from all of you.
 
password is 1234, for user: arnel
password: common for user: common.
 

Users who are viewing this thread

Back
Top Bottom