By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,483 Members | 1,464 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,483 IT Pros & Developers. It's quick & easy.

Hide Command button and form from group of users

P: 42
Created a database that I want to be maintained and updated by the Department designated Admins. I have an user table that set specific individuals access to Admin and created admin form and functions to add data to tables and new users when needed. However, I only want the admins to see the command button on the form to access the Admin form menu. I have been unable to acheive this.
Mar 29 '10 #1

✓ answered by ADezii

Assuming [Admin] is a Yes/No Data Type Field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me![Command13].Visible = DLookUp("[Admin]", "tbl_racifid")
  3. End Sub
Assuming [Admin] is a Text Data Type Field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me![Command13].Visible = (DLookUp("[Admin]", "tbl_racifid") = "Yes")
  3. End Sub

Share this Question
Share on Google+
7 Replies


ADezii
Expert 5K+
P: 8,597
Assuming that your Command Button is named Command1, in the Current() Event of your Form:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me![Command1].Visible = (CurrentUser = "Admin")
  3. End Sub
Mar 29 '10 #2

P: 42
doesn't work. My form is frm_Admin and the command button is Command13. My table that identifies the Admins is tbl_racifid and the field is Admin set to Yes. I have tried Me.Visible statement.
Mar 29 '10 #3

ADezii
Expert 5K+
P: 8,597
Assuming [Admin] is a Yes/No Data Type Field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me![Command13].Visible = DLookUp("[Admin]", "tbl_racifid")
  3. End Sub
Assuming [Admin] is a Text Data Type Field:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Current()
  2.   Me![Command13].Visible = (DLookUp("[Admin]", "tbl_racifid") = "Yes")
  3. End Sub
Mar 29 '10 #4

P: 42
I changed the field type to yes/no and tweek the code a little to read:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.  
  3.   If DLookup("admin", "tbl_racfid", "[Racf_ID] = """ & Form_frm_login.Login_RacfID.Value & """") = True Then
  4.    Me.btn_admin.Visible = True
  5.   Else
  6.    Me.btn_admin.Visible = False
  7.   End If
Mar 29 '10 #5

NeoPa
Expert Mod 15k+
P: 31,186
@ADezii
It's so good to see coders who can handle boolean evaluations properly. So many use the form :
Expand|Select|Wrap|Line Numbers
  1. If X = Y Then
  2.  Z = True
  3. Else
  4.   Z = False
  5. End If
instead of the more sensible :
Expand|Select|Wrap|Line Numbers
  1. Z = (X = Y)
The latter (your code) is so much more succinct and to the point, and shows an understanding of what you're dealing with.
Mar 29 '10 #6

100+
P: 109
Thanks for that comment NeoPa, I realised I have been using the 'less sensible' code for boolean expressions so have gone through my code and altered some of them so it's tidier!
Mar 30 '10 #7

NeoPa
Expert Mod 15k+
P: 31,186
Most people do. There's no shame in starting that way. It's just that when someone (ADezii in this case) shows the way I like to highlight why it's better so people notice and get the point. I'm very pleased to see that you have :)
Mar 30 '10 #8

Post your reply

Sign in to post your reply or Sign up for a free account.