identifying a user

hotmalepiyush

Registered User.
Local time
Today, 09:02
Joined
Jun 3, 2008
Messages
60
i have a multi-user file..which i created using user-level wizard.. now suppose a user logs in and fills up a form.. and adds that as a record.. the form must identify the user and add that to appropiate field in the record.
how can i identify the user and fill the user field.

plz help.
 
You can use a simple function to get user name...
Function GetUserName()
GetUserName = Environ("UserName")
End Function


I usually use an unbound textbox on a form... txtUserName...To display the user name, then on the onOpen event of the form have

Private Sub Form_Open(Cancel As Integer)
Call GetUserName
txtUserName = GetUserName
End Sub

You can then save the "txtUserName" value to a field in your table.
 
thanx for the help
as i am new to access i think i am doing soemthing wrong i encountered two problems..
first, i have tried using several different user accounts.. with different kind of permissions.. but the field taht is supposed to show the user always shows Administrator when the form is opened..

2nd, the field which is supposed to store the user name is blank in the table.how do i save the "txtUserName" value to that field in my table. do i have to explicitly do that using VB code(please suggest if yes)
 
i wud ike to clarify that i used user-level wizard.. nd have formed mny different user accounts.. an i want to idntify these users and not the user acount through which i hav logged on in the OS....
 
If you're using Environ("UserName"), this gives you OS Name. For Access accounts, use CurrentUser() function.

If you're seeing "Admin" as the default user, it may mean that your database is not properly secured.
 
thanx a lot.. using the CurrentUser() function i am able to get the desired result.. but only in the form... when i click the "add record" button all the fields get filled up.. but the one having CurrentUser() remains blank... i have locked the control having user name so that the user can not change it.. please help me find how to fill that field with teh user's name..
 
set the default value of field to CurrentUser()
 
i tried setting CurrentUser() as default. while trying to save i got error message that this is an invalid function.. so i wasnt allowed to save.. :(
 
Khawar has it spot on.

Also, I think you want to realize that you're defeating yourself when you're trying to edit a textbox that you yourself locked. This is same thing as trying to open a door *after* you've locked it, no?

You can use Enabled property to disable the control but still edit it. This isn't without its holes (I've read reports of accidentally editing a disabled control, but don't know the specifics), so you may want to nest your edits like this:

Code:
Me.MyControl.Locked=False
Me.MyControl="foo"
Me.MyControl.Locked=True

But this is really unnecessary, as Default value, as khawar suggested, is much simpler and cleaner.
 
Khawar has it spot on.

Also, I think you want to realize that you're defeating yourself when you're trying to edit a textbox that you yourself locked. This is same thing as trying to open a door *after* you've locked it, no?

You can use Enabled property to disable the control but still edit it. This isn't without its holes (I've read reports of accidentally editing a disabled control, but don't know the specifics), so you may want to nest your edits like this:

Code:
Me.MyControl.Locked=False
Me.MyControl="foo"
Me.MyControl.Locked=True

But this is really unnecessary, as Default value, as khawar suggested, is much simpler and cleaner.

i am not very clear here... i locked the textbox so that the user cannot edit it.. and no matter what he does.. his name goes into the reocrd... is that not what lock is use for??? then what is teh right way to do so..
also i am dunno what ur code does.. it will be kind of u 2 explain it to me..
 
First thing to know about computers is that they're dumber than a bucket of nuts and absolutely has no "common sense". You can't just throw a offhand comment and expect it to know what you implicitly meant. You have to babysit it step by step to do just exactly what you wanted it to do.

In this case, Locked property doesn't mean "Lock this control so users can't edit it", but rather "Lock this control so the data can't be edited by anyone, included myself". This is why I used the analogy of trying to opening a door after you've locked door.

All my code does is unlock the control, insert the value "foo" into the control, then lock it again.

For your case, all you really need is the default value as khawar suggested. I just tested it myself, and it works.

What Access version are you running?
 
am using office 2000 premium.
i am using two files.. front end and back end.. i tried setting the default value of the table in the back end as currentuser() and got "invalid function" as error.

i added your code to my Private Sub AddRecord_Click() and changed "mycontrol" to "called_by" as the textbox is named called by. but i did not get the called by field in my table filled up.am i supposed to paste ur code somewhere else??
i just want two things here,,.,,

(1) the username should come in the form automatically and the user shouldnt be able to tamper it
(2) this username should be filled up in the appropiate field when i click "add record" button..
 
Sorry folks.... I must have misread the post...... My code was to place the user name on a split DB running on a network...:)
 
thsnx a lot banana,, ur link did help me and now i am getting what i wanted
 

Users who are viewing this thread

Back
Top Bottom