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?
Advanced Login System with Admin Privilege?
Collapse
X
-
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
Code:if me!nameofadmincheckbox = true then ' do true stuff else ' do false stuff endif
Jim -
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
Code:if me!nameofadmincheckbox = true then ' do true stuff else ' do false stuff endif
Jim
Code: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
Comment
-
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 :
Code: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
Comment
-
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 :
Code: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
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?Comment
-
Originally posted by NeoPaNeoPa: 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 :
Code: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
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 :
Code:Private strFrom As String Private Sub Form_Open(Cancel As Integer) strFrom = Nz(OpenArgs, "") End Sub
Comment
Comment