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.
12 9289 -
if username="Admin" then
-
me.adduserbtn.visible = true
-
else
-
me.adduserbtn.visible = false
-
end if/
-
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.
post the way you wrote the code, so i can see more specifics...and perhaps a couple user IDs and usernames...
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. - Private Sub Login_button_Click()
-
-
Dim UN, PW As Boolean
-
Dim Name, Lname, Fname As String
-
If IsNull(Me.User_name) Or Me.User_name = "" Then
-
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
-
Me.User_name.SetFocus
-
Exit Sub
-
Else
-
UN = True
-
End If
-
If IsNull(Me.Password) Or Me.Password = "" Then
-
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
-
Me.Password.SetFocus
-
Exit Sub
-
Else
-
PW = True
-
End If
-
If UN = True And PW = True Then
-
If Me.Password.Value = DLookup("[Password]", "Info", "[User ID]='" & Me.User_name & "'") Then
-
DoCmd.Close acForm, Me.Name
-
DoCmd.OpenForm "Info_form"
-
Else
-
MsgBox "Incorrect Password"
-
End If
-
End If
-
End Sub
NeoPa 32,556
Expert Mod 16PB
Try (after line #22) : - Forms("Info_Form").AddNewUser.Visible = (Me.User_Name = "Admin")
NB. Your Dim code on line #3 is equivalent to : - Dim UN As Varian, PW As Boolean
rather than : - Dim UN As Boolean, PW As Boolean
Each variable needs to be set explicitly. The same problem with line #4 of course.
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: - Private Sub Login_button_Click()
-
If IsNull(Me.User_Name) Or Me.User_Name = "" Then
-
MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
-
Me.User_Name.SetFocus
-
Exit Sub
-
End If
-
'the User name has been imputted
-
If IsNull(Me.Password) Or Me.Password = "" Then
-
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
-
Me.Password.SetFocus
-
Exit Sub
-
End If
-
'the Password has been inputted
-
If Me.Password.Value = DLookup("[Password]", "Info", "[User ID]='" & Me.User_Name & "'") Then
-
'Open "Info_form" and pass the User_Name in OpenArgs parameter
-
DoCmd.OpenForm "Info_form", , , , , , Me.User_Name
-
DoCmd.Close acForm, Me.Name
-
Else
-
MsgBox "Incorrect Password"
-
End If
-
End Sub
-
In Info_form form paste the following code: (of course you must change "AdminName" with the real name) - Private Sub Form_Open(Cancel As Integer)
-
Me.AddNewUser.Visible = (Me.OpenArgs = "AdminName")
-
End Sub
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.
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 !.
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 ??
As NeoPa will say... we are happy to help you but new question = new thread.
Okay :) Will start that rite now
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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 =...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |