Option Compare Database
Option Explicit
Private Sub btnCalculator_Click()
Dim calculatorPath As String
calculatorPath = "C:\Windows\System32\calc.exe" ' change the path if necessary
Shell calculatorPath, vbNormalFocus
End Sub
Private Sub btnDemo1_Click()
If IsNull(Me.form1) Then
MsgBox "You do not have permission to open this service", vbInformation, "Notification"
Else
DoCmd.OpenForm (Me.form1)
End If
End Sub
Private Sub btnDemo12_Click()
If IsNull(Me.form12) Then
MsgBox "You do not have permission to open this service", vbInformation, "Notification"
Else
DoCmd.OpenForm (Me.form12)
End If
End Sub
Private Sub btnDemo2_Click()
If IsNull(Me.form2) Then
MsgBox "You do not have permission to open this service", vbInformation, "Notification"
Else
DoCmd.OpenForm (Me.form2)
End If
End Sub
Private Sub btnDemo3_Click()
If IsNull(Me.form3) Then
MsgBox "You do not have permission to open this service", vbInformation, "Notification"
Else
DoCmd.OpenForm (Me.form3)
End If
End Sub
Private Sub btnDemo9_Click()
If IsNull(Me.form9) Then
MsgBox "You do not have permission to open this service", vbInformation, "Notification"
Else
DoCmd.OpenForm (Me.form9)
End If
End Sub
Private Sub btnSettings_Click()
DoCmd.CLOSE
DoCmd.OpenForm "frmSettings"
End Sub
Private Sub cmdAddNewReminders_Click()
DoCmd.OpenForm "frmCreateReminders"
End Sub
Private Sub cmdExit_Click()
DoCmd.Quit
End Sub
Private Sub cmdfrmVAT_Click()
    ' Get the current user's name from the frmHome form
    Dim userFromForm As String
    userFromForm = Forms!frmhome!userName
 
    ' Check if the user's name is not equal to "Ahmed"
    If userFromForm <> "Ahmed" Then
        ' Display a message and don't open frmVAT
        MsgBox "You don't have access to this form.", vbExclamation, "Access Denied"
    Else
        ' Open the frmVAT form
        DoCmd.OpenForm "frmVAT", acNormal
    End If
End Sub
Private Sub CmdRASHED_Click()
    MsgBox "Designed by Ahmed Rashed. If you like, please make for me one espresso without sugar.", vbInformation, "RASHED SOFTWARE"
End Sub
Private Sub cmdReminders_Click()
    ' On Click of the cmdReminders button, check Reminders table for any uncompleted Reminders
    Dim intStore As Integer
    Dim userName As String
    ' Get the username from the form
    userName = Forms!frmhome!userName
    ' Count of uncompleted Reminders that are past the Expected Completion Date
    intStore = DCount("[RemindersID]", "[tblReminders]", "[RemindersDate] <= Now() AND [isComplete] = 0 AND [userName] = '" & userName & "'")
    ' Check if the username matches a specific value (you can replace "YourUsername" with the desired username)
    If userName = Forms!frmhome!userName Then
        ' If the username matches, check the count of uncompleted Reminders
        If intStore = 0 Then
            MsgBox "There are no uncompleted reminders for you."
        Else
            If MsgBox("There are " & intStore & " Reminders " & _
                vbCrLf & vbCrLf & "Would you like to see these now?", _
                vbYesNo, "Reminder") = vbYes Then
                DoCmd.OpenForm "frmReminders"
            End If
        End If
    Else
        ' Handle the case where the username does not match
        MsgBox "You are not authorized to view the reminders."
    End If
End Sub
Private Sub cmdSendMessage_Click()
DoCmd.OpenForm "frmsendMessage", acNormal, "", "", , acNormal
End Sub
Private Sub cmdSwitchUser_Click()
DoCmd.CLOSE
DoCmd.OpenForm "frmLogin"
End Sub
Private Sub cmdViewMessage_Click()
    ' Get the current user's name from the frmHome form
    Dim userFromForm As String
    userFromForm = Forms!frmhome!userName
 
    ' Check if the user's name is not equal to "Ahmed"
    If userFromForm <> "Ahmed" Then
        ' Display a message and don't open frmVAT
        MsgBox "You don't have access to this form.", vbExclamation, "Access Denied"
    Else
        ' Open the frmVAT form
        DoCmd.OpenForm "frmViewMessage", acNormal
    End If
End Sub
Private Sub Form_Load()
DoCmd.Maximize
Dim db As Database
Dim rst As Recordset
Dim userID As Integer
Dim intStore As Integer
Dim userName As String
'This is going to get the userID for the current login from the Temp Table
userID = DLookup("userID", "tTemp", "tempID=1")
Set db = CurrentDb()
'This will collect the information of the current login from the login Table
Set rst = db.OpenRecordset("SELECT *FROM tlogin Where userID=" & userID)
'We are filling the text area on the Demo menu so that we easly access the forms that the user is allowed to use
Me.userName = rst!userName
If rst!allowUserAccessSys = True Then
Me.btnSettings.Visible = True
Else
Me.btnSettings.Visible = False
End If
If rst!form1Allowed = True Then
    Me.form1 = rst!form1
    Me.FormName1 = rst!FormName1
    If IsNull(rst!FormName1) Then
       'Do nothing
    Else
        Me.btnDemo1.Caption = Me.FormName1
    End If
Else
    Me.form1 = Null
    Me.FormName1 = Null
End If
If rst!form11Allowed = True Then
    Me.form11 = rst!form11
    Me.FormName11 = rst!FormName11
     If IsNull(rst!FormName11) Then
       'Do nothing
    Else
    Me.btnDemo11.Caption = Me.FormName11
    End If
Else
    Me.form11 = Null
    Me.FormName11 = Null
End If
If rst!form12Allowed = True Then
    Me.form12 = rst!form12
    Me.FormName12 = rst!FormName12
     If IsNull(rst!FormName12) Then
       'Do nothing
    Else
    Me.btnDemo12.Caption = Me.FormName12
    End If
Else
    Me.form12 = Null
    Me.FormName12 = Null
End If
'We are filing the menuBar
Set rst = db.OpenRecordset("SELECT *FROM tMenu Where menuID=1")
If IsNull(rst!menuBarItemName1) Then
    Me.NavigationButton1.Visible = False
Else
  Me.NavigationButton1.Caption = rst!menuBarItemName1
  Me.menuBarFrmToOpen1 = rst!FormToOpen1
End If
If IsNull(rst!menuBarItemName2) Then
    Me.NavigationButton2.Visible = False
Else
  Me.NavigationButton2.Caption = rst!menuBarItemName2
  Me.menuBarFrmToOpen2 = rst!FormToOpen2
End If
If IsNull(rst!menuBarItemName10) Then
    Me.NavigationButton10.Visible = False
Else
  Me.NavigationButton10.Caption = rst!menuBarItemName10
  Me.menuBarFrmToOpen10 = rst!FormToOpen10
End If
If DLookup("showMenuC", "tstartupForm", "startupID=1") = True Then
    Me.menuCList.Visible = True
End If
    ' On Load of the switchboard (frmhome), check Reminders table for any uncompleted Reminders
' Get the username from the form
userName = Forms!frmhome!userName
' Check the username and show/hide images accordingly
If userName = "ALAA" Then
    Me.ImageALAA.Visible = True
ElseIf userName = "MAHER" Then
    Me.ImageMAHER.Visible = True
ElseIf userName = "AHMED" Then
    Me.ImageAHMED.Visible = True
End If
    ' Count of uncompleted Reminders that are past the Expected Completion Date
    intStore = DCount("[RemindersID]", "[tblReminders]", "[RemindersDate] <= Now() AND [isComplete] = 0 AND [userName] = '" & userName & "'")
    ' Display the reminder count on the form
    Me.ReminderCount.Caption = " " & intStore
    ' Optionally, you can decide whether to open the reminders form or not
    ' If intStore > 0 Then
    '     DoCmd.OpenForm "frmReminders"
    ' End If
 
End Sub
Private Sub Form_Timer()
    Const IDLESECONDS = 1800 ' 1800 seconds of idle time
    Static PrevControlName As String, PrevFormName As String, ExpiredTime
    Dim ActiveFormName As String, ActiveControlName As String, ExpiredSeconds
 
    On Error Resume Next
    ActiveFormName = Screen.ActiveForm.Name
    If Err Then ActiveFormName = "No Active Form": Err = 0
 
    ActiveControlName = Screen.ActiveControl.Name
    If Err Then ActiveControlName = "No Active Control": Err = 0
 
    If (PrevControlName = "") Or (PrevFormName = "") _
        Or (ActiveFormName <> PrevFormName) _
        Or (ActiveControlName <> PrevControlName) Then
        PrevControlName = ActiveControlName
        PrevFormName = ActiveFormName
        ExpiredTime = 0
    Else
        ExpiredTime = ExpiredTime + Me.TimerInterval
    End If
 
    ExpiredSeconds = ExpiredTime / 1000
    If ExpiredSeconds >= IDLESECONDS Then
        ExpiredTime = 0
        Application.Quit ' Quit the application after 1800 seconds of idle time
    End If
Me.Cmes.Requery
Me.AA.Requery
Me.Nmes.Requery
If Me.Cmes.value > 0 Then
DoCmd.OpenForm "frmMessages"
Me.TimerInterval = 0
End If
End Sub
Private Sub Image274_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    MsgBox "Designed by Ahmed Rashed. If you like, please make for me one espresso without sugar.", vbInformation, "RASHED SOFTWARE"
End Sub
Private Sub menuCList_AfterUpdate()
Dim db As Database
Dim rst As Recordset
Set db = CurrentDb()
Set rst = db.OpenRecordset("SELECT *FROM tMenuC Where menuCID=" & menuCList)
Me.menuBarFrmToOpen11 = rst!formToOpen
If IsNull(Me.menuBarFrmToOpen11) Then
MsgBox "You do not have permission to open this service", vbInformation, "Notification"
Else
DoCmd.OpenForm (Me.menuBarFrmToOpen11)
End If
End Sub
Private Sub NavigationButton1_Click()
If IsNull(Me.menuBarFrmToOpen1) Then
MsgBox "You do not have permission to open this service", vbInformation, "Notification"
Else
DoCmd.OpenForm (Me.menuBarFrmToOpen1)
End If
End Sub
Private Sub NavigationButton9_Click()
If IsNull(Me.menuBarFrmToOpen9) Then
MsgBox "You do not have permission to open this service", vbInformation, "Notification"
Else
DoCmd.OpenForm (Me.menuBarFrmToOpen9)
End If
End Sub
Private Sub ReminderCount_Click()
    ' When ReminderCount is clicked, call the cmdReminders_Click procedure
    Call cmdReminders_Click
End Sub