473,396 Members | 1,907 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,396 software developers and data experts.

Advanced Login System with Admin Privilege?

8
I have a database with a table called activeusers and 3 fields. "UserID" "Password" and "Admin". Admin is a yes/no field. I would like to use this field to enable certain buttons on the switchboard screen. how can I use vba to check wether the Admin feild is checked or not?
Jun 23 '10 #1

✓ answered by NeoPa

NeoPa: You need to reconsider your code. It is not reliable as the [Password] is not defined as unique (I hope).

Perhaps, killing two birds with one stone, the following could help :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command8_Click()
  2.     Dim strFilter As String, strAdmin As String
  3.  
  4.     Call Username.SetFocus
  5.     strFilter = "(([UserID]='%U') AND ([Password]='%P'))"
  6.     strFilter = Replace(strFilter, "%U", Me.UserName
  7.     strFilter = Replace(strFilter, "%P", Me.Password
  8.     strAdmin = Nz(DLookup("CStr([Admin])", _
  9.                           "[ActiveUsers]", _
  10.                           strFilter), "Fail")
  11.     If strAdmin = "Fail" Then
  12.         Call MsgBox("Incorrect Username or Password")
  13.     Else
  14.         Call DoCmd.OpenForm(FormName:="MainMenu" _
  15.                            ,OpenArgs:=strAdmin)
  16.         Call DoCmd.Close
  17.     End If
  18. End Sub
If you look at line #15 in the code you'll see this is already passed to the form.

To use this you need to set a variable to this value as soon as the form is opened (as it is lost very soon afterwards). If nothing is passed then OpenArgs is Null.

The code in your called form should be something like :
Expand|Select|Wrap|Line Numbers
  1. Private strFrom As String
  2.  
  3. Private Sub Form_Open(Cancel As Integer)
  4.     strFrom = Nz(OpenArgs, "")
  5. End Sub

7 3938
jimatqsi
1,271 Expert 1GB
In the switchboard program, you will want to either set the .visible property or the .enabled property of the buttons you want to turn on or off.

The code will be
Expand|Select|Wrap|Line Numbers
  1. if me!nameofadmincheckbox = true then
  2.    ' do true stuff
  3. else
  4.     ' do false stuff
  5. endif
  6.  
You might want to put this code in the OnLoad event of the form and also on the click event of whatever buttons moves to another user ID. Or maybe you want to put it in after the password is checked. Probably there is best, after they login you will turn the buttons on or off.

Jim
Jun 23 '10 #2
rhuns
8
@jimatqsi
I apologize I may not have been as clear as I needed to be. There are two forms I have: one a login and one a menu. I want certain buttons enabled to certain users and other buttons not enabled to certain users. Is there a way I set the current record through the login screen? Here is the code I have so far:

Expand|Select|Wrap|Line Numbers
  1. Private Sub Command8_Click()
  2. Username.SetFocus
  3. If Username = DLookup("UserID", "ActiveUsers", "[password] = '" & Password & "'") Then
  4.     DoCmd.Close
  5.     DoCmd.OpenForm "MainMenu"
  6. Else
  7.     MsgBox "Inncorrect Username or Password"
  8. End If
  9. End Sub
Jul 4 '10 #3
NeoPa
32,556 Expert Mod 16PB
You need to reconsider your code. It is not reliable as the [Password] is not defined as unique (I hope).

Perhaps, killing two birds with one stone, the following could help :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command8_Click()
  2.     Dim strFilter As String, strAdmin As String
  3.  
  4.     Call Username.SetFocus
  5.     strFilter = "(([UserID]='%U') AND ([Password]='%P'))"
  6.     strFilter = Replace(strFilter, "%U", Me.UserName
  7.     strFilter = Replace(strFilter, "%P", Me.Password
  8.     strAdmin = Nz(DLookup("CStr([Admin])", _
  9.                           "[ActiveUsers]", _
  10.                           strFilter), "Fail")
  11.     If strAdmin = "Fail" Then
  12.         Call MsgBox("Incorrect Username or Password")
  13.     Else
  14.         Call DoCmd.OpenForm(FormName:="MainMenu" _
  15.                            ,OpenArgs:=strAdmin)
  16.         Call DoCmd.Close
  17.     End If
  18. End Sub
Jul 5 '10 #4
rhuns
8
@NeoPa
Neopa,

I tried your code and it works!

However, how would make the distinction of and Admin vs. a regular user?

I.E.:

I want certain buttons, like addnewbtn, or, updatebtn, only enabled to Administrators, not regular users. How could this be accomplished?
Jul 6 '10 #5
NeoPa
32,556 Expert Mod 16PB
NeoPa: You need to reconsider your code. It is not reliable as the [Password] is not defined as unique (I hope).

Perhaps, killing two birds with one stone, the following could help :
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command8_Click()
  2.     Dim strFilter As String, strAdmin As String
  3.  
  4.     Call Username.SetFocus
  5.     strFilter = "(([UserID]='%U') AND ([Password]='%P'))"
  6.     strFilter = Replace(strFilter, "%U", Me.UserName
  7.     strFilter = Replace(strFilter, "%P", Me.Password
  8.     strAdmin = Nz(DLookup("CStr([Admin])", _
  9.                           "[ActiveUsers]", _
  10.                           strFilter), "Fail")
  11.     If strAdmin = "Fail" Then
  12.         Call MsgBox("Incorrect Username or Password")
  13.     Else
  14.         Call DoCmd.OpenForm(FormName:="MainMenu" _
  15.                            ,OpenArgs:=strAdmin)
  16.         Call DoCmd.Close
  17.     End If
  18. End Sub
If you look at line #15 in the code you'll see this is already passed to the form.

To use this you need to set a variable to this value as soon as the form is opened (as it is lost very soon afterwards). If nothing is passed then OpenArgs is Null.

The code in your called form should be something like :
Expand|Select|Wrap|Line Numbers
  1. Private strFrom As String
  2.  
  3. Private Sub Form_Open(Cancel As Integer)
  4.     strFrom = Nz(OpenArgs, "")
  5. End Sub
Jul 6 '10 #6
rhuns
8
NeoPa,

Your code worked perfectly! Thanks so much! I've been stuck for over a week trying to debug this one. Thanks again!
Jul 7 '10 #7
NeoPa
32,556 Expert Mod 16PB
I'm pleased to have been able to help :)
Jul 7 '10 #8

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

Similar topics

2
by: Geiregat Jonas | last post by:
I'm running a linux system I would like to create a login system based upon the users and passwd of my linux box how could I do this ?
18
by: R. Rajesh Jeba Anbiah | last post by:
This is regarding secure login implementation in PHP. I'm trying to understand <http://mail.yahoo.com/> If I understand right, they're passing the md5 hash instead of the password itself. But, I...
6
by: R. Rajesh Jeba Anbiah | last post by:
Q: How to implement a login system? A: Use sessions. When the user logins, store the session id in the database and then compare the current session id with the one stored in the database on every...
8
by: frizzle | last post by:
Hi group, I need a login system for some 'private' pages. Users should be pulled from a mysql DB. Now, i've read a lot on login systems, and somehow there's _always_ the discussion with...
1
blyxx86
by: blyxx86 | last post by:
Is setting up a username/password system very difficult? What is the code, like Environ(), but specific for the username used to log into the database? We are going to be using my database at...
13
by: walterbyrd | last post by:
For real, could php-cli be useful for system admin tasks? I doubt php-cli will ever match perl, or python, for a sys admin scripting language. But, does php-cli come close enough to the sys...
2
by: inspirer | last post by:
hi there first of all thanks 4 this helpfull forum i just have one question and i will be very thankful to get ur ansmwer back what are the common problems of system admin???????
5
by: makaman | last post by:
Heys guys, i really need help bad. i'm making a program, and i only want registered ppl to use it, but i'm having lots of problems. i want to make a advanced login system, so that the username and...
13
by: Apostle | last post by:
Hi all, after thinking for sometimes, I thought it will be great opportunity to learn if I will start from scratch and build my own register/login system. Here is the thread that I will be posting...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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
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...
0
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,...

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.