you dont need to store passords, just let windows authentication. They use their own user/password.
Code:
SUB btnLogin_Click()
Dim sUser As String, sPass As String, sDom As String
sUser = txtUser
sPass = txtPass
sDom = "CoDomain"
if sUser = Dlookup("userid","tUsers","[userid]='" & sUser & "'") then
If WindowsLogin(sUser, sPass, sDom) Then
mbSafe = True
DoCmd.OpenForm "frmMainMenu"
DoCmd.OpenForm "frmLogin"
DoCmd.Close
Else
MsgBox "LOGIN INCORRECT", vbCritical, "Bad userid or password"
End If
end if
end sub
'-----------------
Public Function WindowsLogin(ByVal strUserName As String, ByVal strpassword As String, ByVal strDomain As String) As Boolean
'-----------------
'Authenticates user and password entered with Active Directory.
On Error GoTo IncorrectPassword
Dim oADsObject, oADsNamespace As Object
Dim strADsPath As String
strADsPath = "WinNT://" & strDomain
Set oADsObject = GetObject(strADsPath)
Set oADsNamespace = GetObject("WinNT:")
Set oADsObject = oADsNamespace.OpenDSObject(strADsPath, strDomain & "\" & strUserName, strpassword, 0)
WindowsLogin = True 'ACCESS GRANTED
ExitSub:
Exit Function
IncorrectPassword:
WindowsLogin = False 'ACCESS DENIED
Resume ExitSub
End Function
First the db is on the network, so users already have to login to windows.
In the db, I have a tUsers table, with userID, Name, and Level
USERID, FIRSTN, LASTN, LEVEL
bob12, bob smith, M
pam4, pam jones,""
xman, charles, xavier, F
when user opens the db, the main menu form will open and grab the userID.
Then lookup that persons rights in order to enable/disable controls.
Code:
public gvUserID
sub form_load()
dim vLevel
gvUserID = Environ("Username") 'get userID,visible in all forms
'get level from user table
vLevel = Dlookup("[Level]","tUsers","[userID]='" & gvUserID & "'")
'now, enable/disable items on form
select case vLevel
case "A" 'admin
'all is enabled
case "U" 'normal user
txtBox1.enabled = false
txtManager.enabled = false
case "M" 'manager
txtBox1.enabled = false
end select
end sub