Simple Password form, need code!!

DaniBoy

Registered User.
Local time
Today, 23:14
Joined
Nov 18, 2001
Messages
174
Hello, I have a table that links to the Employees table called "SecurityPassword". In this table I can pick an employee from the Employee table and set a username and password for that employee. I have a button on my switchboard that opens up a form that I created. This form has 2 unbound fields "Username" and "Password" and want to make a botton that checks for the for the username and password in the SecurityPassword table and if it matches to open the requested object on the switchboard link.

Can you help me?

DaniBoy
 
All you need to do when the button is clicked is to do a DLookUp on the 2 values (Username & Password) in the table to see if they match what the user has entered e.g.

Dim strPassword As String
Dim strUserName As String
Dim intResponse As Integer

strPassword = Me.txtPassword
strUserName = Me.txtUsername

If strPassword = DLookup("Password", "SecurityPassword", "UserName = '" & strUserName & "'") Then let them in

Else

intResponse = MsgBox("You have entered an incorrect Username and/or Password" & vbCrLf & vbCrLf _
& "Please try again!.", vbCritical + vbOKOnly, _
"Access Denied")

End If

The only thing I would say is that securing a database in this way is very unsecure unless you encrypt the data. Otherwise anybody could just open the SecurityPassword table and see Username & Passwords.
 
Thank you

I just need it for simple useage on a database, thanks a lot!!

DaniBoy
 
One more question !!!

One more before the weekend!!!

in code how do I tell it to open a switchboard


EX:

If txtPassword = "55" then

"Open switchboard"

else

msgBox "no good"
 
To open the switchboard if someone successfully enters a correct username & password do the following:

First declare the following variables under the ones previously declared above:

Dim stDocName As String
Dim stLinkCriteria As String

Then where you've got "Open switchboard" put the following:

stDocName = "Switchboard"
DoCmd.OpenForm stDocName, , , stLinkCriteria

And that should be it.

Let me know if I can be of any further help.
 
Thanks

Thanks, works fine but still not doing what I need it to do,

Ok, am actualy already clicking on a botton on my first switchboard. This opens my security form, from there I want it to open another switchboard that is the Administrators Switchboard.

Thanks

DaniBoy
 
Ok, one more thing!!

I have it so that the code only checks for the username and password, what if I have another criteria that I want it to check?

I decided to put this password form at the start of the application and I added a field on the security table called "Position" that has a combo with Administration or Regular, I want it to go find the username and password and Position, but if it position is a Regular to open one form and if it is a Administration to open another.

This is what I got:

Private Sub Command32_Click()
Dim strClave As String
Dim strUsuario As String
Dim intResponse As Integer

strClave = Me.Clave
strUsuario = Me.Usuario

If strClave = DLookup("Clave", "tblSeguridad", "Usuario = '" & strUsuario & "'") Then
DoCmd.Close
DoCmd.OpenForm "frmMenuPrincipal", , , "[ItemNumber] = 0 AND [SwitchboardID]=" & 3

Else

intResponse = MsgBox("Nombre de Usuario o Clave Incorrecta" & vbCrLf & vbCrLf _
& "Por favor trate de nuevo!.", vbCritical + vbOKOnly, _
"Acceso Negado")

End If

End Sub
 
Ok, what you need is this:


Private Sub Command32_Click()
Dim strClave As String
Dim strUsuario As String
Dim strPosition As String
Dim intResponse As Integer

strClave = Me.Clave
strUsuario = Me.Usuario
strPosition = Me.Position

If strClave = DLookup("Clave", "tblSeguridad", "Usuario = '" & strUsuario & "'") AND strPosition = "Regular" Then
DoCmd.Close
DoCmd.OpenForm "frmMenuPrincipal", , , "[ItemNumber] = 0 AND [SwitchboardID]=" & 3

ElseIf strClave = DLookup("Clave", "tblSeguridad", "Usuario = '" & strUsuario & "'") AND strPosition = "Administration" Then
DoCmd.Close
DoCmd.OpenForm "frmMenuPrincipal", , , "[ItemNumber] = 0 AND [SwitchboardID]=" & 3


Else

intResponse = MsgBox("Nombre de Usuario o Clave Incorrecta" & vbCrLf & vbCrLf _
& "Por favor trate de nuevo!.", vbCritical + vbOKOnly, _
"Acceso Negado")

End If

End Sub


The additional code is in red. All you need to do is change the form names for if they are Regular or Administration.

Good Luck
 
Thnak you

Thanks a lot for the help, I will go try this code

DaniBoy
 

Users who are viewing this thread

Back
Top Bottom