Hello,
I am using this code I found on this forum quite some time ago. It has served me well.
I was wondering if there was some easy way to add a check box that would allow a user to "Save" their username and password so they do not have to plug it in each time they go into the DB.
This code is in a Module.
Thanks. Fen How
Option Compare Database
Option Explicit
Public Type UserInfo
UserID As String
UserName As String
UserPassword As String
UserLevel As Integer
End Type
Public User As UserInfo
Function LogUserOff()
On Error GoTo Err_LogUserOff
'Requires the reference to Microsoft DAO 3.6 Object Library to be set.
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblLogTimes", dbOpenDynaset)
rst.FindLast "UserID = " & User.UserID
rst.Edit
rst!LoggedOut = Now()
rst.Update
User.UserLevel = 0
Exit_LogUserOff:
Exit Function
Err_LogUserOff:
Resume Exit_LogUserOff
End Function
Function LogUserOn()
On Error GoTo Err_LogUserOn
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tbllogtimes", dbOpenDynaset)
With rst
.AddNew
![UserID] = User.UserID
.Update
End With
Exit_LogUserOn:
Exit Function
Err_LogUserOn:
Resume Exit_LogUserOn
End Function
Function IsLoaded(ByVal strFormName As String) As Boolean
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
Function SetProps(ByVal strForm As String)
With Forms(strForm)
Select Case User.UserLevel
Case 1 'Admin Permissions
Case 2 'Manager Permissions
Case 3 'User Permissions
Case 4 'Guest Permissions
Case Else 'No UserLevel set
DoCmd.Close acForm, strForm
End Select
End With
End Function
I am using this code I found on this forum quite some time ago. It has served me well.
I was wondering if there was some easy way to add a check box that would allow a user to "Save" their username and password so they do not have to plug it in each time they go into the DB.
This code is in a Module.
Thanks. Fen How
Option Compare Database
Option Explicit
Public Type UserInfo
UserID As String
UserName As String
UserPassword As String
UserLevel As Integer
End Type
Public User As UserInfo
Function LogUserOff()
On Error GoTo Err_LogUserOff
'Requires the reference to Microsoft DAO 3.6 Object Library to be set.
Dim db As DAO.Database
Dim rst As DAO.Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("tblLogTimes", dbOpenDynaset)
rst.FindLast "UserID = " & User.UserID
rst.Edit
rst!LoggedOut = Now()
rst.Update
User.UserLevel = 0
Exit_LogUserOff:
Exit Function
Err_LogUserOff:
Resume Exit_LogUserOff
End Function
Function LogUserOn()
On Error GoTo Err_LogUserOn
Dim dbs As DAO.Database
Dim rst As DAO.Recordset
Set dbs = CurrentDb
Set rst = dbs.OpenRecordset("tbllogtimes", dbOpenDynaset)
With rst
.AddNew
![UserID] = User.UserID
.Update
End With
Exit_LogUserOn:
Exit Function
Err_LogUserOn:
Resume Exit_LogUserOn
End Function
Function IsLoaded(ByVal strFormName As String) As Boolean
Const conObjStateClosed = 0
Const conDesignView = 0
If SysCmd(acSysCmdGetObjectState, acForm, strFormName) <> conObjStateClosed Then
If Forms(strFormName).CurrentView <> conDesignView Then
IsLoaded = True
End If
End If
End Function
Function SetProps(ByVal strForm As String)
With Forms(strForm)
Select Case User.UserLevel
Case 1 'Admin Permissions
Case 2 'Manager Permissions
Case 3 'User Permissions
Case 4 'Guest Permissions
Case Else 'No UserLevel set
DoCmd.Close acForm, strForm
End Select
End With
End Function