473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Button visible only for Admin and not to users

Hi , I have a login page(form1),when we enter the login page it takes to a new form(form3) to view their informations.And i have a button to add new users,Who ever enters the form can access the button called "Add New User".
but i want to make it visible only when the "ADMIN" log in. Please help me I am new to Access.
Apr 3 '12 #1
12 9289
Expand|Select|Wrap|Line Numbers
  1. if username="Admin" then
  2. me.adduserbtn.visible = true
  3. else
  4. me.adduserbtn.visible = false
  5. end if/
  6.  
Apr 3 '12 #2
Hi Stev,
Thanks for your help. I tried this code and it is just hiding the button for all the users, I mean even for the ADMIN. Please help.
let me give you the full details. "User_name" comes from the table1 ie from "User ID". So on loading the form , if it is ADMIN then it should have access. plz help me.
Apr 3 '12 #3
post the way you wrote the code, so i can see more specifics...and perhaps a couple user IDs and usernames...
Apr 3 '12 #4
Hi Steve,
This is the Code which i have rite now.
So when i login as ADMIN , the "addnewuser" button in the "infoform" should should show up and it should get hidden for other users.
Expand|Select|Wrap|Line Numbers
  1. Private Sub Login_button_Click()
  2.  
  3. Dim UN, PW As Boolean
  4. Dim Name, Lname, Fname As String
  5.     If IsNull(Me.User_name) Or Me.User_name = "" Then
  6.       MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
  7.         Me.User_name.SetFocus
  8.         Exit Sub
  9.     Else
  10.     UN = True
  11.     End If
  12.       If IsNull(Me.Password) Or Me.Password = "" Then
  13.       MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
  14.         Me.Password.SetFocus
  15.         Exit Sub
  16.         Else
  17.         PW = True
  18.          End If
  19.   If UN = True And PW = True Then
  20.  If Me.Password.Value = DLookup("[Password]", "Info", "[User ID]='" & Me.User_name & "'") Then
  21.     DoCmd.Close acForm, Me.Name
  22.     DoCmd.OpenForm "Info_form"
  23. Else
  24.    MsgBox "Incorrect Password"
  25.    End If
  26.    End If
  27. End Sub
Apr 3 '12 #5
NeoPa
32,556 Expert Mod 16PB
Try (after line #22) :
Expand|Select|Wrap|Line Numbers
  1. Forms("Info_Form").AddNewUser.Visible = (Me.User_Name = "Admin")
NB. Your Dim code on line #3 is equivalent to :
Expand|Select|Wrap|Line Numbers
  1. Dim UN As Varian, PW As Boolean
rather than :
Expand|Select|Wrap|Line Numbers
  1. Dim UN As Boolean, PW As Boolean
Each variable needs to be set explicitly. The same problem with line #4 of course.
Apr 4 '12 #6
Mihail
759 512MB
I think that the button visibility should be handle in the Info_form form using _Open event.
I have cleaned a little bit your code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub Login_button_Click()
  2.     If IsNull(Me.User_Name) Or Me.User_Name = "" Then
  3.         MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
  4.         Me.User_Name.SetFocus
  5. Exit Sub
  6.     End If
  7.     'the User name has been imputted
  8.     If IsNull(Me.Password) Or Me.Password = "" Then
  9.         MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
  10.         Me.Password.SetFocus
  11. Exit Sub
  12.     End If
  13.     'the Password has been inputted
  14.     If Me.Password.Value = DLookup("[Password]", "Info", "[User ID]='" & Me.User_Name & "'") Then
  15.         'Open "Info_form" and pass the User_Name in OpenArgs parameter
  16.         DoCmd.OpenForm "Info_form", , , , , , Me.User_Name
  17.         DoCmd.Close acForm, Me.Name
  18.     Else
  19.         MsgBox "Incorrect Password"
  20.     End If
  21. End Sub
  22.  

In Info_form form paste the following code: (of course you must change "AdminName" with the real name)
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_Open(Cancel As Integer)
  2.     Me.AddNewUser.Visible = (Me.OpenArgs = "AdminName")
  3. End Sub
Apr 4 '12 #7
NeoPa
32,556 Expert Mod 16PB
Mihail:
I think that the button visibility should be handle in the Info_form form using _Open event.
Why?

It's certainly a way to handle it, but I don't see why it would be preferable necessarily.
Apr 4 '12 #8
Mihail
759 512MB
Because a form can be opened from many places.
This way, the form itself handle their controls. This avoid to handle this situation in every place (other forms or codes) from where this form can be opened.
And, NeoPa, I say "I think" not "must".
Another reason is to reduce the risk. For exemple I am not sure that your solution (Try (after line #22)... - post #6) can work. Because the line #21.
I repeat: I am not sure. Maybe work, maybe not.
It is why I have inverted line #21 with line #22 (#16, #17 in my post).
Lastly, "I think" that because this approach is better fit to my style in programming :)

Cheers !.
Apr 4 '12 #9
Hi NeoPa and Mihail
Thanks a lot for your help, both the codes are working and when it works without using boolean and varian, why do we need it ?? And also i need one more help.

When a user login , it should show only the user's data, so when it login to the info form it should show their corresponding form.. how to make that ??
Apr 4 '12 #10
Mihail
759 512MB
As NeoPa will say... we are happy to help you but new question = new thread.
Apr 4 '12 #11
Okay :) Will start that rite now
Apr 4 '12 #12
NeoPa
32,556 Expert Mod 16PB
Mihail:
For example I am not sure that your solution (Try (after line #22)... - post #6) can work. Because the line #21.
Good thinking, but the form cannot close while the form's module code is still running. It's a bit of a silly line to have in the code at that place, but one can't always comment on every problem with members' code as there can be so many.
Apr 4 '12 #13

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

Similar topics

1
by: PCB | last post by:
Hi all, Not sure if this is possible, but can I change the controls of a command button on a per record bases in a subform. In my case, I would like to make a command button visible only if...
1
by: Marc Lefebvre | last post by:
Why I was unable to hide the previous button in the following code ? private void ButtonClick(Object sender, System.EventArgs e) { Button button = (Button)sender; Button previousButton =...
6
by: tshad | last post by:
I have 2 buttons: <asp:ImageButton ID="ExpandButton" runat="server" Font-Size="2" ImageUrl="../images/expand.jpg" Width="16" Height="16" CommandName="Select" AlternateText="Click here to see...
0
by: Eric Butler | last post by:
I am trying to get user information out of AD (specifically the memberOf property) from an ASP.net page and am having a strange problem. If the user I query for is an administrator in the domain...
2
by: Jéjé | last post by:
Hi, I have create some webpart controls to use in sharepoint. these webparts are in a DLL and I have a resource file for the french language. after an IISReset, if the caller is a...
5
by: Doogie | last post by:
Hi, I am trying to access the visible property of an ASP button inside javascript to no avail. Here's what my button control looks like: <asp:Button id="btnAcceptTrips" name="btnAcceptTrips"...
4
by: peerraghu | last post by:
hi I am creating travels project, in left part of my datagrid of my default page i placed all the products such as india tour ,world tour etc and if v click any product it will redirect to...
2
by: somacore | last post by:
I have a webform in C#. This form has both a gridview and a formview. The formview displays the details of the selected gridview index. No problem there. On the formview is a button. When this...
4
by: Essnell | last post by:
Hi, I'd like to know if it is possible to have a form containing a number of buttons that run query searches for showing availability of members on specific days as the only visible part of the...
3
greeni91
by: greeni91 | last post by:
Hi There, I have created a database that has been implemented in our workshop for over a year now and this is our first problem... actually quite a biggie in my mind. One of the users in the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.