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?
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 : - Private Sub Command8_Click()
-
Dim strFilter As String, strAdmin As String
-
-
Call Username.SetFocus
-
strFilter = "(([UserID]='%U') AND ([Password]='%P'))"
-
strFilter = Replace(strFilter, "%U", Me.UserName
-
strFilter = Replace(strFilter, "%P", Me.Password
-
strAdmin = Nz(DLookup("CStr([Admin])", _
-
"[ActiveUsers]", _
-
strFilter), "Fail")
-
If strAdmin = "Fail" Then
-
Call MsgBox("Incorrect Username or Password")
-
Else
-
Call DoCmd.OpenForm(FormName:="MainMenu" _
-
,OpenArgs:=strAdmin)
-
Call DoCmd.Close
-
End If
-
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 : - Private strFrom As String
-
-
Private Sub Form_Open(Cancel As Integer)
-
strFrom = Nz(OpenArgs, "")
-
End Sub
7 3938
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 - if me!nameofadmincheckbox = true then
-
' do true stuff
-
else
-
' do false stuff
-
endif
-
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
@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: - Private Sub Command8_Click()
-
Username.SetFocus
-
If Username = DLookup("UserID", "ActiveUsers", "[password] = '" & Password & "'") Then
-
DoCmd.Close
-
DoCmd.OpenForm "MainMenu"
-
Else
-
MsgBox "Inncorrect Username or Password"
-
End If
-
End Sub
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 : - Private Sub Command8_Click()
-
Dim strFilter As String, strAdmin As String
-
-
Call Username.SetFocus
-
strFilter = "(([UserID]='%U') AND ([Password]='%P'))"
-
strFilter = Replace(strFilter, "%U", Me.UserName
-
strFilter = Replace(strFilter, "%P", Me.Password
-
strAdmin = Nz(DLookup("CStr([Admin])", _
-
"[ActiveUsers]", _
-
strFilter), "Fail")
-
If strAdmin = "Fail" Then
-
Call MsgBox("Incorrect Username or Password")
-
Else
-
Call DoCmd.OpenForm(FormName:="MainMenu" _
-
,OpenArgs:=strAdmin)
-
Call DoCmd.Close
-
End If
-
End Sub
@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?
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 : - Private Sub Command8_Click()
-
Dim strFilter As String, strAdmin As String
-
-
Call Username.SetFocus
-
strFilter = "(([UserID]='%U') AND ([Password]='%P'))"
-
strFilter = Replace(strFilter, "%U", Me.UserName
-
strFilter = Replace(strFilter, "%P", Me.Password
-
strAdmin = Nz(DLookup("CStr([Admin])", _
-
"[ActiveUsers]", _
-
strFilter), "Fail")
-
If strAdmin = "Fail" Then
-
Call MsgBox("Incorrect Username or Password")
-
Else
-
Call DoCmd.OpenForm(FormName:="MainMenu" _
-
,OpenArgs:=strAdmin)
-
Call DoCmd.Close
-
End If
-
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 : - Private strFrom As String
-
-
Private Sub Form_Open(Cancel As Integer)
-
strFrom = Nz(OpenArgs, "")
-
End Sub
NeoPa,
Your code worked perfectly! Thanks so much! I've been stuck for over a week trying to debug this one. Thanks again!
NeoPa 32,556
Expert Mod 16PB
I'm pleased to have been able to help :)
Sign in to post your reply or Sign up for a free account.
Similar topics
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 ?
|
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...
|
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...
|
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...
|
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...
|
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...
|
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???????
|
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...
|
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...
|
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...
|
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: 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...
|
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...
|
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: 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: 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...
|
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,...
| |