This is the way I was taught to do it a school, don't know if it is what you
are looking for or not. Create a new module, use this code, you will have to
change the names of the forms and the user types to suit your need. No
guarantees but it works fine forme. I am still some what new at this and if
possible would like to contribute back to this forum.
Good luck
' Name: procLogin
' Purpose: Validate username/ password
' Parameters: Username and password entered as a string
' Called by: frmLogin
Sub procLogin(UserName As String, Pwd As String)
' 1.0 variable for a database connection
Dim dbsConnection As Database
' 1.1 variable for a recordset object
Dim rsUser As Recordset
Dim sqlString As String
Dim UserType As String
' 1.2 Connect to database by calling a module function.
Set dbsConnection = procConnectToDatabase()
' 1.3 Validate UserName Password UserType
sqlString = "SELECT tblUser.UserID, tblUser.UserName, tblUser.Password,
tblUser.UserTypeID, tblUserType.UserType" & _
" FROM tblUserType INNER JOIN tblUser ON tblUserType.UserTypeID =
tblUser.UserTypeID" & _
" WHERE (((tblUser.UserName)='" & UserName & "') AND ((tblUser.Password)='"
& Pwd & "'));"
Set rsUser = dbsConnection.OpenRecordset(sqlString)
' 1.4 When finished close the recordset object
' if at eof(End OF File) didnt find a match
If rsUser.EOF Then
procDisplayMessage ("You don't seem to be in our system")
Forms!frmLogin!txtUsername.SetFocus
' 1.5 If user is found open one of the appropriate forms
Else
'Close Login Form
DoCmd.Close
If rsUser!UserType = "System Manager" Then
DoCmd.OpenForm "frmSwitchboardSM", , , , , , rsUser!UserTypeID
Else
If rsUser!UserType = "Employee" Then
DoCmd.OpenForm "frmSwitchboardSM", , , , , , rsUser!UserTypeID
Else
If rsUser!UserType = "Customer" Then
DoCmd.OpenForm "frmSwitchboardCustomer", , , , , , rsUser!UserTypeID
End If
End If
End If
End If
' 1.6 when finished close record set and close database connection
rsUser.Close
dbsConnection.Close
Exit Sub
End Sub