password problem??

jaison2

New member
Local time
Today, 13:19
Joined
Dec 7, 2008
Messages
5
hi,

for my project i have done all the things including password... but the problem is that... i currently have two passwords one for manager and one for the staff which when entered take them to two different switchboards with different access rights.... i created the passwords in a form with VBA coding....but i want to know whether you can get the password screen which is an FORM at the start of the database... i.e.when you open the database you should get a screen asing for user ID and password?..

thx...
 
In Tools/Startup, make that the startup form.
 
This works for me. This is in the on click event for the submit button in the login form. Code validates user login info, then opens appropriate switchboard. Also, user that is currently logged in is stored in a public module which can be referenced to in other forms.

Code:
Option Compare Database
Option Explicit

Public lngLogAttempts As Long
Const Mssg1 = "  Please Enter User Name and Password.   "
Const Mssg2 = "Logon Details Incorrect... User Not Found.    "
Const Title1 = " Logon Error"
Const Mssg3 = " Password must be typed identically."

Private Sub cboLogin_AfterUpdate()
    Me.txtPsswd.SetFocus
End Sub

Private Sub cmdSubmit_Click()
    Dim db As DAO.Database
    Dim rst As DAO.Recordset
    Dim strSQL As String
    Set db = CurrentDb()
    strSQL = "SELECT * FROM tblEmployee WHERE [EmployeeID] = " & Me.cboLogin.Value
'CHECKING FOR NULLS
        If IsNull(Me.cboLogin) Then
            MsgBox Mssg1, vbCritical, Title1
            Me.cboLogin.SetFocus
            Call CheckLogAttempts
        ElseIf IsNull(Me.txtPassword) Then
            MsgBox Mssg1, vbCritical, Title1
            Me.txtPassword.SetFocus
            Call CheckLogAttempts
'VALIDATING PASSWORD
        Else
            If Me.txtPassword.Value = DLookup("Password", "tblEmployee", "[EmployeeID]=" & Me.cboLogin.Value) Then
            
'PASSING VARIABLES TO DB
                Set rst = db.OpenRecordset(strSQL, dbOpenDynaset)
                With User
                    .CurrentUser = rst.Fields("EmployeeID")
                End With
                rst.Close
'Open Appropriate Home Form
                If Me.txtPassword.Value = "changeme" Then
                DoCmd.OpenForm "frmchangePassword", acNormal, , "EmployeeID=" & Me!cboLogin, acFormEdit, acDialog
                Else
                           Dim strAccessLevel As String
                           Dim strForm As String
                    
                           strAccessLevel = Nz(DLookup("UserTypeID", "tblEmployee", "[EmployeeID]=" & Me.cboLogin.Value), "4")
                    
                           Select Case strAccessLevel
                           
                           Case 1
                           strForm = "frmHome"
                           Case 2
                           strForm = "frmHomeOperator"
                           Case 3
                           strForm = "frmHomeManager"
                           Case 4
                           strForm = "frmHomeUser"
                           End Select
                           Me.Visible = False
                           DoCmd.OpenForm strForm
                           Me.Visible = False
                           End If
                

'Close Login Form
            Else
                MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
                Me.txtPassword.SetFocus
                Call CheckLogAttempts
            End If
        End If
End Sub
 
Private Sub CheckLogAttempts()
    If lngLogAttempts >= 2 Then
        MsgBox "     It appears you are having trouble logging on.    " & Chr(13) & "Please contact your System Administrator " & "for assistance.       ", vbCritical, Title1
        DoCmd.CloseDatabase
    Else
        lngLogAttempts = lngLogAttempts + 1
    End If
End Sub

Private Sub Form_Load()
On Error GoTo Err_Form_Load
    Me.cboLogin.SetFocus
    lngLogAttempts = 0
Exit_Form_Load:
    Exit Sub
Err_Form_Load:
    MsgBox err.Description, , " LogOn Error"
    Resume Exit_Form_Load
End Sub


Here is the module I use.
Code:
Option Compare Database

Option Explicit

Public Type UserInfo
    CurrentUser As Long
End Type

Public User As UserInfo
 
If the password is the default 'changeme', then the form open is the change password form. Here is the code on that form.

Code:
Option Compare Database
Option Explicit

Public lngLogAttempts As Long
Const Mssg1 = "  Please Enter User Name and Password.   "
Const Mssg2 = "Password is not typed correctly.    "
Const Title1 = " Logon Error"
Const Mssg3 = " Password cannot be 'changeme'."
Const Mssg4 = "Password is not typed correctly."


Private Sub cmdSubmit_Click()
If Me.txtPassword2.Value <> Me.txtPassword Then
MsgBox Mssg4, vbCritical, Title1
End If
If Me.txtPassword.Value = "changeme" Then
MsgBox Mssg3, vbCritical, Title1
End If
If Me.txtPassword2.Value = Me.txtPassword And Me.txtPassword2.Value <> "changeme" Then
DoCmd.Close acForm, "frmchangepassword", acSaveYes
End If
End Sub

Private Sub Form_Close()
Dim strAccessLevel As String
Dim strForm As String

strAccessLevel = Nz(DLookup("UserTypeID", "tblEmployee", "[EmployeeID]=" & Me.EmployeeID.Value), "4")

Select Case strAccessLevel

Case 1
strForm = "frmHome"
Case 2
strForm = "frmHomeOperator"
Case 3
strForm = "frmHomeManager"
Case 4
strForm = "frmHomeUser"
End Select
Me.Visible = False
[Forms]![frmlogin].Visible = False
DoCmd.OpenForm strForm

End Sub
 
In Tools/Startup, make that the startup form.

i did this but still you can just close the login form and access the other forms.. i want it to prevent this.. if the login form is closed then nothing should be available...
 
Presuming you want to stay with your own security and not use the built-in variety, options including not displaying the database window, disabling the shift key on startup and either only giving users the runtime version of Access or forcing them into runtime mode.
 
What he said!

Also, you can make your login form Modal, and disable the 'x' button.
 

Users who are viewing this thread

Back
Top Bottom