473,543 Members | 3,135 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Button visible only for Admin and not to users

9 New Member
Hi , I have a login page(form1),whe n we enter the login page it takes to a new form(form3) to view their informations.An d 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 9305
kstevens
74 New Member
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
ashok srmuniv
9 New Member
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
kstevens
74 New Member
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
ashok srmuniv
9 New Member
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,563 Recognized Expert Moderator MVP
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 Contributor
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,563 Recognized Expert Moderator MVP
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 Contributor
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
ashok srmuniv
9 New Member
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

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

Similar topics

1
4189
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 certain fields in a table are a certain value. The buttons are adjacent to each record (i.e. - if there are 5 records, there would be 5 buttons; 10...
1
3300
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 = (Button)Session; if( previousButton == null ) {
6
2810
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 details"></asp:ImageButton> <asp:ImageButton ID="CollapseButton" visible="false" runat="server" Font-Size="2" ImageUrl="../images/collapse.jpg"...
0
951
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 then I get a complete list of all properties, including the one I need. However, if the user that I query for is not an admin, I get back a much more...
2
2334
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 non-administrator user, then the language resource file is not loaded. if an administrator load the page, then the DLL is found and loaded into the cache and...
5
16293
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" runat="server" Text="Accept Trips" Visible="False"> Here's my test method: function test(checkbox)
4
2493
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 itennary page according to their ID's my problem is i inserted new product as Hotel Booking and i want to place textbox and a button in the itenary page...
2
3326
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 button is clicked it sends an email to the DBAs asking for a database request to be run. This works as well. However I would like to idiot proof...
4
2511
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 access DB. This is for a small Museum and we don't want every one getting into the DB. I have tried as in my previous question 2 weeks ago, which I...
3
1435
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 workshop has been tinkering with parts of the database and has caused me a lot of hastle. I have tried deleting his account but keep getting errors, I...
0
7402
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7590
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7344
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7684
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
5883
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5264
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4890
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3391
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
963
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.