Option Compare Database
Option Explicit
Public dbPA As DAO.Database
Public rsUser As Recordset
Private Sub Form_Close()
' MsgBox rsUser.Fields("Full_Name")
' Now we clear the logged in flag to identify anyone left logged in when tring to update/amend the back end.
With rsUser
.Edit
.Fields("Logged_in").Value = False
.Update
End With
rsUser.Close
Set rsUser = Nothing
Set dbPA = Nothing
Application.Quit acQuitSaveAll
End Sub
Private Sub Form_Open(Cancel As Integer)
'This form will control what form will be used as startup depending on the user name (FileID) in Windows.
' If an FL, they will get the control form, if PA, just the allocation form
Dim strOpenForm As String, strSQL As String, strUser As String, strRole As String, blnFlow_Leader As Boolean
Dim intRecordCount As Integer
Dim strReqPath As String
On Error GoTo Err_Handler
strReqPath = "C:\Program Files\PA Allocation"
'First make sure user is running their own accde file on their computer
If InStr(CurrentProject.Name, "accde") > 0 Then
If CurrentProject.Path <> strReqPath Then
MsgBox "Incorrect database opened, this will now close"
Application.CloseCurrentDatabase
End If
Else
MsgBox "WARNING - This is not the accde file"
End If
'Using the TempVar collection for any global variables
TempVars("G_File_ID").Value = Environ("USERNAME")
TempVars("G_Full_Name").Value = ""
strUser = TempVars("G_File_ID").Value
strSQL = "SELECT User.Full_Name, User.Role,User.Flow_leader, User.Logged_In FROM User WHERE (((User.File_ID)='" & strUser & "'));"
'MsgBox strSQL
Set rsUser = CurrentDb.OpenRecordset(strSQL)
' If no record found then EOF is true
If Not rsUser.EOF Then
intRecordCount = rsUser.RecordCount
TempVars("G_Full_Name") = rsUser.Fields("Full_Name").Value
strRole = rsUser.Fields("Role").Value
blnFlow_Leader = rsUser.Fields("Flow_Leader").Value
Else
MsgBox "Unable to locate User for User ID " & strUser
Exit Sub
End If
' Now we set the logged in flag to identify anyone left logged in when tring to update/amend the back end.
With rsUser
.Edit
.Fields("Logged_in").Value = True
.Update
End With
'Recordset and database now closed in Close event when database closes
' rsUser.Close
' Set rsUser = Nothing
' Set dbPA = Nothing
' Cancel opening of this form
' Cancel = True
' Now we open specific form
If intRecordCount > 0 Then
If strRole = "FL" Then
strOpenForm = "FL_Control"
Else
If strRole = "PA" Then
strOpenForm = "PA_Work_Allocation"
Else
strOpenForm = "FT_Work_Allocation"
End If
End If
End If
DoCmd.OpenForm strOpenForm
Err_Exit:
Exit Sub
Err_Handler:
MsgBox "Error " & Err.Number & " " & Err.Description
Resume Err_Exit
End Sub