Login in Access 2007

Hi Everyone,

I need some VBA coding to handle a two different kinds of users entering passwords in.  I have my code for an administration user when they enter password in, but I nned to have some coidng where when an ordinary user enterss their password a different menu form opens up.

My Coding:

Private Sub Form_Open(Cancel As Integer)
'On open set focus to combo box
Me.cboEmployee.SetFocus
End Sub

Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
Me.txtPassword.SetFocus
End Sub

Private Sub cmdLogin_Click()

'Check to see if data is entered into the UserName combo box

    If IsNull(Me.cboEmployee) Or Me.cboEmployee = "" Then
            MsgBox "You must enter a User Name.", vbOKOnly, "Required Data"
            Me.cboEmployee.SetFocus
        Exit Sub
    End If

'Check to see if data is entered into the password box

    If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
            MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
            Me.txtPassword.SetFocus
        Exit Sub
    End If

'Check value of password in tblEmployees to see if this matches value chosen in combo box

    If Me.txtPassword.Value = DLookup("strEmpPassword", "tblEmployees", "[lngEmpID]=" & Me.cboEmployee.Value) Then

        lngMyEmpID = Me.cboEmployee.Value

'Close logon form and open splash screen

       
       
       
        DoCmd.Close acForm, "frmLogon", acSaveNo
        DoCmd.OpenForm "Startup Screen"

        Else
        MsgBox "Password Invalid.  Please Try Again", vbOKOnly, "Invalid Entry!"
        Me.txtPassword.SetFocus
    End If
   
    End If

I have an Employee table that holds the User

with these fields:  lngEmpId, StrEmpName, StrEmpPassword, and StrAccess.


jjc9809Asked:
Who is Participating?
 
Rey Obrero (Capricorn1)Commented:
change the ROwSource of your combo box to


 SELECT [tblEmployees].[lngEmpID], [tblEmployees].[strEmpName], [tblEmployees].[strAccess] FROM tblEmployees;
0
 
peter57rCommented:
How do you identify whether the user is an Admin user and an ordinary user?
0
 
Rey Obrero (Capricorn1)Commented:
include the field "strAccess" in the rowsource of your combo box "cboEmployee", then in the afterupdate event, check the value of "strAccess" and proceed accordingly to open the "menu"


Private Sub cboEmployee_AfterUpdate()
'After selecting user name set focus to password field
'Me.txtPassword.SetFocus

select case me.cboEmployee.column(3)  'refers to the "strAccess" field
      case "admin"

       '  your codes here
 
     case "user"
         'your codes here

       
 

end select

End Sub



got the idea ?
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
jjc9809Author Commented:
Capricorn,

On the Row Source Select Statement, I put this:  SELECT [tblEmployees].[lngEmpID], [tblEmployees].[strEmpName].[strAccess] FROM tblEmployees;

I get error when it runs if you place the [strAccess] in there.

0
 
Rey Obrero (Capricorn1)Commented:


change this part

   select case me.cboEmployee.column(3)


with

    select case me.cboEmployee.column(2)


*note, set the column count property of the combo to  3

0
 
jjc9809Author Commented:
I get the attached error when I select the drop down for obo.employee:


ERROR--5-.pdf
0
 
jjc9809Author Commented:
I finally got it to work.

Thanks
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.