Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code help to allow use of a checkbox based on User ID 2

Status
Not open for further replies.

BoatingGirl

Programmer
Feb 24, 2004
7
US
I've hit a stumbling block in coding, which isn't a very big suprise, because I only understand the basics of VBA. I haven't figured out how to write my own original code yet, I keep relying on examples in books, and I can't find an example that speaks what I need done.

What I'm trying to do is limit who can check a checkbox in a form based on the user. If the person trying to put a check in the box is not one of the users with permission then they will get an error message telling them they do not have permission. I am using Access 2002 its built-in security.

Example: In a form I have a checkbox labled "BoatingGirl" and when I am logged in as BoatingGirl I can put a check in that box. But when BoatingBoy logs in he would not be allowed to check the box and would get an error message box that says "You are not allowed to do that!"

About the only thing that I can code is the Message Box.

I am trying to teach myself VBA as quickly as I can, but unfortunately my company's current need has outpaced me.

Thank you in advance for any help!
-=BG=-
 
If you have a small finite list of users which it sounds like you could use code in the forms OnOpen event procedure to enable and disable certain controls on the form. It would change depending upon who is logged when the form is opened.

EXAMPLE:
All of these special checkboxes would have their .enabled property set to FALSE to start with.

On Open Event Procedure code:
Code:
Select Case CurrentUser()
   Case  "BoatingGirl"
       Me![BoatingGirl].enabled = True
   Case   "BoatingBoy"
       Me![BoatingGirl].enabled = True
   Case   . . . 

End Select

After the user leaves the form the controls are reset back to .enabled = False and when the next user logs on the enabled controls would change depending upon the CurrentUser().

Post back if you have any questions.

Bob Scriver
[blue]Want the best answers? See FAQ181-2886[/blue]


 
Hi

If you are using Access security then CurrentUser() returns the logged in user id

so at its most basic in the before update event of the check box:

If CurrentUser() <> "BoatingGirl" Then
MsgBox "No permission to do this"
Cancel = True
End if



Regards

Ken Reay
Freelance Solutions Developer
Boldon Information Systems Ltd
Website needs upgrading, but for now - UK
 
Thank you both!!!

Your suggestions helped a lot and worked wonderfully!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top