Hi there,
I don't know quite how to phrase this question, but hopefully I can get the point across. I have two forms: an administrator login form and a main navigation form.
I want my system to be able to recognize if the administrator is logged in to then display a "logout" button on the main navigation form. The way I had thought to accomplish this was by creating a variable (loggedIn as Boolean) in the code for my login form which sets to True if the username and password provided are correct. How do I then use my loggedIn variable in the code for my main navigation form?
I know it has something to do with defining it as a public variable, but when I call the variable on the navigation form it gives me False (which I assume is the default value).
Here is the login form code:
Code:
Public loggedIn As Boolean
Public Sub Command4_Click()
If Me.username = "a" And Me.password = "0" Then
DoCmd.SelectObject acTable, , True
DoCmd.ShowToolbar "Ribbon", acToolbarYes
DoCmd.Close acForm, "AdminLoginF"
loggedIn = True
DoCmd.Close acForm, "Switchboard"
DoCmd.OpenForm "Switchboard"
Else
MsgBox "Incorrect username and/or password."
Me.password = ""
Me.username.SetFocus
loggedIn = False
End If
Navigation:
Code:
Public Sub Form_Activate()
If loggedIn = False Then 'loggedIn from forms!AdminLoginF - public variable indicating whether or not the user is the admin or not.
DoCmd.SelectObject acTable, , True
DoCmd.RunCommand acCmdWindowHide 'hide navigation pane
DoCmd.ShowToolbar "Ribbon", acToolbarNo 'hide ribbon
Command7.Enabled = True
Command7.Visible = True
Command8.Enabled = False
Command8.Visible = False
Else
Command7.Enabled = False
Command7.Visible = False
Command8.Enabled = True
Command8.Visible = True
MsgBox "Hello"
End If
End Sub
thanks,
jmd