Setting a field to editable based on Windows Login

kleaves

Registered User.
Local time
Today, 10:34
Joined
Nov 21, 2006
Messages
25
I have a field within a form, which I want all the users of the database to see, but I only want it to be editable if your windows logon name is one of the following:

kleaves
jbloggs
Jsmith

I know I can use the environ variable - environ ("username") and I think I should set this code under the properties of this field possibly the on click setting. Can anyone help?

The reason why I want to do it by Windows logon as this form is widely used by many people and there is no logging into the form at startup. I currently have set the changing of this field to be recorded in a historical view, But I still need to restrict the entry to this field.
 
Your code should go in the Current event of the form. Dont forget the Else LockIt code! Since you currently have three users to allow I would create a table of authorized users rather than hard code their names. If User in the table then UnLock the control Else LockIt!
 
Last edited:
I have a table of Users, where has two columns, Col1 = Username, col2=Auth Code. So I could say something Like:

If users.[auth code] = 'M'
then UnlockIt
Else LockIt

Is this correct?
 
You will need to do a DLookup in the Users table to find the record you want. To speed things up considerably, I would do the DLookup in the initial form and then just set this form's Visible property to false. You need to keep this form open throughout the current session. Then Forms!InitialForm!AuthCode will return the Authorization code without the delay of a DLookup. You need to use your form and control names of course!
 
If this is the only form where you will be limiting the users editing capacity then you can do the DLookup in the OnLoad event of the form and save their Authorization Code in a local variable for use in the Current event of the form.
 
Thanks Rural Guy

Will have a play around with this and see where I get to !!

Thanks again
 
Help

I'm having a nightmare with this. I have set the field (AuthorisedBy) on the form to Locked = True within the properties. Checked this worked and although a user can see the drop down, they cannot select another value. (This is fine)

The next step is to only allow users whose windows logon = my table Authorisers.winlogon to edit this field

My Table is set out as below:

WinLogon (This is primary key which holds the users windows login name)
UserName (Text field - Holds the userName - Used as the text for the drop down on the form)

I have tried to user Unlockit and lockit but cannot get the syntax correct.

I was thinking something like on the On Click Event of the AuthorisedBy field on the form

If Environ("UserName") = Authorisers.WinLogon then unlockit else lockit

This does not work - Can someone help - Please !!!
 
Sample Database

Check out the sample I have created for you. The Test form will open for you at start up and because your name is not in the list you won't be able to add, delete, or edit records. Once you put your computer login user name into the table (use the frmUsers form) and select the permission level, you will be able to open the test form and do what your permission level is set to.
 

Attachments

Users who are viewing this thread

Back
Top Bottom