Yes/No Checkbox Lock field in form

anujgem

New member
Local time
Today, 15:36
Joined
Jun 19, 2012
Messages
4
Hello,

I am a beginner in SQL and VB. I have the following issue:

I have a form that has Yes/No Checkbox. However, I want to control this checkbox based on user ID. I searched on internet and i found module that will create a function called "getusername". Now i have created a query with this fucntion that gives the current user id.

I am not able to figure out how to lock checkbox based on the query result. For example if the query result is "ABC" user will not be able click on the checkbox.

Your help and assistance is greatly appreciated....
 
If all you want to do is lock a checkbox based on the user then place an unbound text box in the form by the checkbox (call the text box 'User'), you can hide it by setting it invisible. Place this in its source:
Code:
= Environ("USERNAME")
Then under form events --> on open --> type
Code:
If Me.User = "user you dont want clicking check box" Or "another user?" Then
Me.Checkbox.enabled=false
Else
Me.Checkbox.enabled=true
End If
If you have a big list of users you probably would want to make a table to store the list of users and use a dlookup to reference them instead.
 
Thanks a lot for replying....

However user ID is dynamic. That is the function "getusername" gets the windows log in ID of the user who access the database. I have written a query which when executes give me the windows log ID say "ABCD".

I want to lock the checkbox based on the result of the query. I tried your method but it give me an error compile error. Sorry I am novice in access. Your help is greatly appreciated...

Thanks

Anuj
 
Im guessing this is your function:
Code:
function GetUserName()
GetUserName = Environ("UserName")
end function
Environ will return the username that you use to log into windows with. If you want to post your database, I will set it up for you. I would only need the list of users you dont want clicking the checkbox. You can post it by clicking 'Go Advanced' I believe, though you may need 5 or 10 posts minimum before you can
 
Thanks a lot..

I have attached the db. I want to lock the checkbox if the user is "guptaan". Also would it be possible to provide a save button on the form so that if the user clicks that button then only the form updates the table.

Thanks a ton....
 

Attachments

alright here you go, I wasn't sure what you wanted with the save button...when you enter data into a field within the form it is automatically entered into the table, but i threw in a save button just in case. The compile issue you had earlier was because you had attempted to write some code but left it incomplete.
 

Attachments

Users who are viewing this thread

Back
Top Bottom