GetUserID

How can you do it Minty

Read the link. Create the module, on starting your app it will automatically get the user ID and set is the value of the property.
Where ever you need it just refer to it as if it was a global constant.
 
i think it GetUserID is related to your Login Form.
see this demo.
Arnel, do we need to make this on the on unload event of the loginForm?
Private Sub Form_Unload(Cancel As Integer)
If Len(Me.UserID & "") = 0 Then
Application.Quit
End If
End Sub

Because I have tried to adopt your suggestion to mine, the same problem existed like before. Syntax Error " Mismatch type"
 
is UserId a text string or a number?
GetuserId sounds like a function that returns the active UserId - so does that return a string or a number

The expression you quoted treats UserId as a string - and tests whether the string has a value or not.
So if UserId is defined as a number, this expression will give a type mismatch. You can't just treat a number as if it was a string

If Len(Me.UserID & "") = 0 Then

I would probably do it this way, but it's still assuming UserId is a string.
if nz(Me.UserID,"")="" then
 
is UserId a text string or a number?
GetuserId sounds like a function that returns the active UserId - so does that return a string or a number

The expression you quoted treats UserId as a string - and tests whether the string has a value or not.
So if UserId is defined as a number, this expression will give a type mismatch. You can't just treat a number as if it was a string

If Len(Me.UserID & "") = 0 Then

I would probably do it this way, but it's still assuming UserId is a string.
if nz(Me.UserID,"")="" then
UserID is a autonumber
 
Which user ID are you trying to get? Is that the same as the network login or Username?
I think is UserID when we login, because the purpose is only Admin, that can edit itemcode in the "Edit Item Form". because I locked the itemCode field in the form, when common user open it
 
is UserId a text string or a number?
GetuserId sounds like a function that returns the active UserId - so does that return a string or a number

The expression you quoted treats UserId as a string - and tests whether the string has a value or not.
So if UserId is defined as a number, this expression will give a type mismatch. You can't just treat a number as if it was a string

If Len(Me.UserID & "") = 0 Then

I would probably do it this way, but it's still assuming UserId is a string.
if nz(Me.UserID,"")="" then
It hang here Gemma, fyi I do not have userID field in the form, I just have user name and password to fill.
hangatGetuserID.jpg
 
so you have a function GetUserId, returning a long number - the top line of your function

if you already have an id, GetUserUd returns the Id, but you never set ID to a value, so this won't work.
if you don't have an ID, it opens "LoginForm" in dialog mode, so before your program can carry on, the LoginForm must close first. That's what acDialog does.

You then try to set GetUserID to a value on the "LoginForm", but because that form is no longer open, this must give you a run time error.

You appear to be mixing up a few things in the way you are trying to use your login form, so it isn't working in quite the way you want.
 
so you have a function GetUserId, returning a long number - the top line of your function

if you already have an id, GetUserUd returns the Id, but you never set ID to a value, so this won't work.
if you don't have an ID, it opens "LoginForm" in dialog mode, so before your program can carry on, the LoginForm must close first. That's what acDialog does.

You then try to set GetUserID to a value on the "LoginForm", but because that form is no longer open, this must give you a run time error.

You appear to be mixing up a few things in the way you are trying to use your login form, so it isn't working in quite the way you want.
Yes Gemma, it seems I just make a simple way, on the Admin Form, I just make a button to open a form of Edit Item, in edit mode when open. It is more simple.

Thank you,
 
GetUserID is a UDF (User Defined Function) It should be somewhere in your database. If you got the rest of the code from someone here or a different app, go back to where you got the rest of the code and pick up the GetUserID function.

Otherwise,
Look at your table to see what the user id's look like. The Environ() solution might pick that up for you. But typically a userId is entered in a log in form.
 
GetUserID is a UDF (User Defined Function) It should be somewhere in your database. If you got the rest of the code from someone here or a different app, go back to where you got the rest of the code and pick up the GetUserID function.

Otherwise,
Look at your table to see what the user id's look like. The Environ() solution might pick that up for you. But typically a userId is entered in a log in form.
Obtained from this thread I believe?
https://www.utteraccess.com/topics/2060624/posts/2775103
 

Users who are viewing this thread

Back
Top Bottom