How to disable a sub-form in ms access form - access-vba

I had this project where I have to make a program with a login and different levels of access according to which user loged in. So i made the login form and after that i had this form where it have three sub-forms, each labeled level_1-3. The idea is if the user has access level 1 the two sub-forms will be disabled and the first form only will be enabled.
the code i used looks something like this
If Not rs.EOF Then
Acesslevel = DLookup("[Access_level]", "managers_data", "username.Value")
MsgBox " Welcome " & username.Value & ". Acess level " & Acesslevel & " Granted!!"
DoCmd.Close
If Acesslevel = 1 Then
DoCmd.OpenForm "Home"
x
If Acesslevel = 2 Then
DoCmd.OpenForm "Home"
y
If Acesslevel = 2 Then
DoCmd.OpenForm "Home"
z
so my question is what code should i insert in places of x so that the two sub-forms (sub-form level_2 and level_3 are disabled and level_1 is enabled) and the same question goes for y and z. the name of the form is home. and i am using ms access 2013. Any help will be appreciated, thanks.

It could be:
<snip>
DoCmd.Close
DoCmd.OpenForm "Home"
Forms!Home!SubformControlX.Enabled = False
Forms!Home!SubformControlY.Enabled = False
Forms!Home!SubformControlZ.Enabled = False
Select Case Acesslevel
Case 1
Forms!Home!SubformControlX.Enabled = True
Case 2
Forms!Home!SubformControlY.Enabled = True
Case 3
Forms!Home!SubformControlZ.Enabled = True
End Select

Related

#Name? on form after requery in Access 2010

I am using VBA and SQL to re-query my main form based on criteria entered in several controls on a pop up form. As far as I can tell the code is running correctly, the database is re-queried based on the criteria I enter, but 2 of my controls on my main form show as #Name? or blank after re-querying based on the criteria. Anyone know how I can fix this???
The code that runs the re-query is:
Public Sub SuperFilter()
On Error GoTo Err_AdvancedFilter_Click
Dim strSQL As String
Dim strCallNumber As String
Dim strAsgnTech As String
Dim strClientID As String
Dim strCallGroup As String
Dim strPriority As String
Dim strOpenStatus As String
If IsNull(Forms![frmTips&Tricks].txtCallNumber) = False Then
strCallNumber = " (((CallInfo.CallNumber) = forms![frmTips&Tricks].[txtCallNumber])) and "
Else
strCallNumber = ""
End If
If IsNull(Forms![frmTips&Tricks].cboAsgnTech) = False Then
strAsgnTech = " (((CallInfo.AsgnTech) = forms![frmTips&Tricks].[cboasgntech])) and "
Else
strAsgnTech = ""
End If
If IsNull(Forms![frmTips&Tricks].cboClientID) = False Then
strClientID = " (((CallInfo.ClientID) = forms![frmTips&Tricks].[cboClientID])) and "
Else
strClientID = ""
End If
If IsNull(Forms![frmTips&Tricks].cboCallGroup) = False Then
strCallGroup = " (((CallInfo.AsgnGroup) = forms![frmTips&Tricks].[cboCallGroup])) and "
Else
strCallGroup = ""
End If
If IsNull(Forms![frmTips&Tricks].cboPriority) = False Then
strPriority = " (((CallInfo.Severity) = forms![frmTips&Tricks].[cboPriority])) and "
Else
strPriority = ""
End If
If Forms![frmTips&Tricks].optOpenStatus.Value = 1 Then
strOpenStatus = " (((CallInfo.OpenStatus) = True))"
Else
strOpenStatus = " (((CallInfo.OpenStatus) is not null ))"
End If
strSQL = "SELECT CallInfo.CallNumber, CallInfo.ClientID,* " & _
"FROM dbo_HDTechs INNER JOIN ([User] INNER JOIN CallInfo ON User.ClientID = CallInfo.ClientID) ON dbo_HDTechs.TechName = CallInfo.AsgnTech " & _
"WHERE " & strCallNumber & strAsgnTech & strClientID & strCallGroup & strPriority & strOpenStatus & _
"ORDER BY CallInfo.RcvdDate;"
Form.RecordSource = strSQL
Me.cboCallNumber.RowSource = strSQL
Form.Requery
If Me.RecordsetClone.RecordCount = 0 Then
MsgBox "No Records Found: Try Diferent Criteria."
Form.RecordSource = "qryservicerequestentry"
Me.cboCallNumber.RowSource = "qryservicerequestentry"
Exit Sub
End If
Me.cmdSuperFilterOff.Visible = True
Exit Sub
Exit_cmdAdvancedFilter_Click:
Exit Sub
Err_AdvancedFilter_Click:
MsgBox Err.Description
Resume Exit_cmdAdvancedFilter_Click
End Sub
The first control in question is a combo box that displays the Client Name from the CallInfo form (Main Form).
Control Source: ClientID
And when expanded lists all available clients to select from the Users form (User ID is linked between the User form and CallInfo form).
Row Source: SELECT User.ClientID FROM [User];
After the re-query, this combobox will be blank, sometimes showing #Name? if you click on it.
The second control in question is a text box that shows the Client's phone number.
Control Source: PhoneNo
After the Re-query, this text box always displays #Name?
The third control in question is a text box that displays the clients office location.
Control Source: Location
What really baffles me is that THIS text box displays correctly after the re-query. I don't know why it would display the correct data when the Phone Number text box does not, seeing as they are so similar and work with similar data....
To Compare, the The form record source is normally based on:
SELECT CallInfo.CallNumber, CallInfo.ClientID, CallInfo.RcvdTech, CallInfo.RcvdDate, CallInfo.CloseDate, CallInfo.Classroom, CallInfo.Problem, CallInfo.CurrentStatus, CallInfo.Resolution, CallInfo.Severity, CallInfo.OpenStatus, CallInfo.AsgnTech, dbo_HDTechs.Email, CallInfo.FullName, CallInfo.AsgnGroup, User.Location, User.PhoneNo, CallInfo.OpenStatus
FROM dbo_HDTechs INNER JOIN ([User] INNER JOIN CallInfo ON User.ClientID = CallInfo.ClientID) ON dbo_HDTechs.TechName = CallInfo.AsgnTech
WHERE (((CallInfo.OpenStatus)=True))
ORDER BY CallInfo.RcvdDate;
Just going on what you wrote, I may take a slightly different approach (just personal preference).
I would change all of your 'IsNull' tests to also check for 'Empty'. i.e.
If IsNull(Forms![frmTips&Tricks].cboClientID) = False AND ...cliientID <> ""
Just today I had an issue relating to form references in a query WHERE clause, so I changed to:
strClientID = " (((CallInfo.ClientID) = '" & forms![frmTips&Tricks].[cboClientID] & "')) and"
Add a Debug.Print of your generated SQL, then look at it and try to run that SQL manually
Good Luck,
Wayne
Solved by designating the form in the control source like: CallInfo.ClientID
I still don't know why the Client Office displayed Correctly... Anybody have a hint? :)
TE

DoCmd.OpenForm crashing Access 2010

I have a user login form on my access database with a table of users and other user criteria. One is a checkbox that if "true" will open up a change password form when the following code is ran. But when this checkbox field returns true, access 2010 crashes. So far, Google has left me empty handed. Any ideas on what would be causing the crash? Is it something in the code or could it be an issue with the "change password" form? The form opens just fine when I manually open it by "double clicking" it.
'Check if password needs to be reset
If Me.cboUser.Column(3) = True Then
DoCmd.OpenForm "frmPasswordChange", , , "UserID = " & Me.cboUser
End If
The entire code is this:
Private Sub txtPassword_AfterUpdate()
'Check that EE is selected
If IsNull(Me.cboUser) Then
MsgBox "You need to select a user!", vbCritical
Me.cboUser.SetFocus
Else
'Check for correct password
If Me.txtPassword = Me.cboUser.Column(2) Then
'Check if password needs to be reset
If Me.cboUser.Column(3) = True Then
DoCmd.OpenForm "frmPasswordChange", , , "UserID = " & Me.cboUser
End If
DoCmd.OpenForm "Opening Screen"
Me.Visible = False
DoCmd.SetWarnings False
DoCmd.RunSQL ("INSERT INTO tblAuditTrail ([DateTime], UserName, Action) VALUES (Now(),'" & Me.cboUser.Column(1) & "','Login')")
DoCmd.SetWarnings True
Else
MsgBox "Password does not match, please re-enter!", vboOkOnly
Me.txtPassword = Null
Me.txtPassword.SetFocus
End If
End If
End Sub

Access VBA using Multiple button.visible = False

I have a login screen I am using to control access to buttons in my main Navigation form. I want the users security level to determine which buttons are visible. My problem is if I try to add more than one button.visible = False then the form breaks and I see all but the top button I tried to make invisible. I'm pretty new at coding VBA (I basically just bought a book last week) and I'm hopihn I'm just missing something simple. Can anyone help? Code is below.
Private Sub Command1_Click()
Dim User As String
Dim UserLevel As Integer
Dim TempPass As String
Dim ID As Integer
Dim workerName As String
Dim TempLoginID As String
Dim SecLevel As String
If IsNull(Me.txtUserName) Then
MsgBox "Please enter UserName", vbInformation, "Please Enter your HealthcareID this is the same Id you use to log into windows"
Me.txtUserName.SetFocus
ElseIf IsNull(Me.txtPassword) Then
MsgBox "Please enter Pin Number", vbInformation, "Please enter your Pin Number"
Me.txtPassword.SetFocus
Else
If IsNull(DLookup("UserLogin", "tblUser", "UserLogin = '" & Me.txtUserName.Value & "' And password = '" & Me.txtPassword.Value & "'")) Then
MsgBox "Invalid UserName or Password! Use your HealthcareID as your username and your pin code to access."
Else
TempLoginID = Me.txtUserName.Value
workerName = DLookup("[UserName]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
UserSecurity = DLookup("[UserSecurity]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
TempPass = DLookup("[password]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
Unit = DLookup("[Unit]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
Unit = DLookup("[Unit]", "tblUser", "[UserLogin] = '" & Me.txtUserName.Value & "'")
DoCmd.Close
Select Case UserSecurity
Case Is = 1 'Admins
DoCmd.OpenForm "Navigation Form"
Forms![Navigation Form]![TxtUser] = workerName
Forms![Navigation Form]![txtName] = TempLoginID
Forms![Navigation Form]![txtUnit] = Unit
Forms![Navigation Form]![txtUserSecurity] = UserSecurity
' DoCmd.BrowseTo acBrowseToForm, "frmFirstPage", "Navigation Form.NavigationSubForm", , , acFormEdit
Case Is = 2 'Managers
DoCmd.OpenForm "Navigation Form"
Forms![Navigation Form]![TxtUser] = workerName
Forms![Navigation Form]![txtName] = TempLoginID
Forms![Navigation Form]![txtUnit] = Unit
Forms![Navigation Form]!AdminPageButton.Visible = False
Forms![Navigation Form]![txtUserSecurity] = UserSecurity
' DoCmd.BrowseTo acBrowseToForm, "frmFirstPage", "Navigation Form.NavigationSubForm", , , acFormEdit
Case Is = 3 'Coordinators
DoCmd.OpenForm "Navigation Form"
Forms![Navigation Form]![TxtUser] = workerName
Forms![Navigation Form]![txtName] = TempLoginID
Forms![Navigation Form]![txtUnit] = Unit
Forms![Navigation Form]![txtUserSecurity] = UserSecurity
Forms![Navigation Form]!btnManagersMenu.Visible = False
Forms![Navigation Form]!AdminPageButton.Visible = False
' DoCmd.BrowseTo acBrowseToForm, "frmFirstPage", "Navigation Form.NavigationSubForm", , , acFormEdit
Case Else 'RCRs
DoCmd.OpenForm "Navigation Form"
Forms![Navigation Form]![TxtUser] = workerName
Forms![Navigation Form]![txtName] = TempLoginID
Forms![Navigation Form]![txtUnit] = Unit
Forms![Navigation Form]![txtUserSecurity] = UserSecurity
Forms![Navigation Form]!AdminPageButton.Visible = False
Forms![Navigation Form]!btnManagersMenu.Visible = False
Forms![Navigation Form]!btnCoordMenu.Visible = False
' DoCmd.BrowseTo acBrowseToForm, "frmFirstPage", "Navigation Form.NavigationSubForm", , , acFormEdit
End Select
End If
End If
End Sub
I'm quite new to Access and VBA myself, so without seeing your navigation form setup I'm not quite sure why your subsequent buttons remain visible when you're opening the form like this. However, you could try moving your Select Case UserSecurity code into the Form_Load sub of your navigation form - I do something similar with my forms at the Form_Load and Form_Current subs and I have multiple command buttons, text fields etc becoming visible or invisible depending on different criteria, including the users security level. This is an example of a sub I use on one form -
Private Sub Form_Current()
On Error GoTo Form_Current_Err
Me.txtOrderStatus.Requery 'refresh the order status
'move the cursor to the end of the PO No field
Me.txtPONo.SetFocus
If Not IsNull(Me.txtPONo) Then
Me.txtPONo.SelStart = Len(Me.txtPONo)
End If
'make the contract no and project description fields visible only when the PO is related to a contract
If txtPOType.Value = "Contract" Then
Me.txtContractNo.Visible = True
Me.txtProjectDescription.Visible = True
Me.txtParentPO.Visible = False
Me.POTabs.Pages(6).Visible = False
ElseIf Me.txtPOType.Value = "Call Off Order" Then 'make the parent po visible if this is a call off order
Me.txtContractNo.Visible = False
Me.txtProjectDescription.Visible = False
Me.txtParentPO.Visible = True
Me.POTabs.Pages(6).Visible = True
Else
Me.txtContractNo.Visible = False
Me.txtProjectDescription.Visible = False
Me.txtParentPO.Visible = False
Me.POTabs.Pages(6).Visible = False
End If
'check if the order is cancelled and hide all action buttons
If Me.OrderStatus = "Cancelled" Then
Me.cmdEditPO.Visible = False
Me.cmdCancelOrder.Visible = False
Me.txtCancelledOrderFlag.Visible = True
Me.AmendedOrderFlag.Visible = False
Else
Me.cmdEditPO.Visible = True
Me.txtCancelledOrderFlag.Visible = False
End If
'check if this a revised order and hide the Amended Order comment and the PO Revisions subform if it isn't
If txtPORevision > 0 Then
If Me.OrderStatus <> "Cancelled" Then
Me.AmendedOrderFlag.Visible = True
Me.PO_Revisions.Visible = True
Else
Me.AmendedOrderFlag.Visible = False
Me.PO_Revisions.Visible = True
End If
Else
Me.AmendedOrderFlag.Visible = False
Me.PO_Revisions.Visible = False
End If
'check if the PO needs approval and the user is a PO Approver,
' and make the approve/cancel buttons visible as appropriate
If Me.OrderStatus = "For Approval" And _
(DLookup("Role", "dbo_Employees", "EmployeeID = " & TempVars!EmpID) = "Administrator" _
Or DLookup("Role", "dbo_Employees", "EmployeeID = " & TempVars!EmpID) = "Manager") Then
'show the Approve PO button, hide the Cancel button
Me.cmdApproveOrder.Visible = True
Me.cmdCancelOrder.Visible = False
Else
'hide the Approve button, show the Cancel button
Me.cmdApproveOrder.Visible = False
If Me.OrderStatus <> "Cancelled" Then
Me.cmdCancelOrder.Visible = True
End If
End If
'if the order hasn't been approved yet, or is cancelled, hide the email button
If Me.OrderStatus = "New" Or Me.OrderStatus = "Raised" Or Me.OrderStatus = "For Approval" _
Or Me.OrderStatus = "Not Approved" Or Me.OrderStatus = "Cancelled" Then
Me.cmdEmailPO.Visible = False
Else
Me.cmdEmailPO.Visible = True
End If
'amend the caption of the Revise order button if the order has not been sent yet
If Me.OrderStatus = "New" Or Me.OrderStatus = "Raised" Then
Me.cmdEditPO.Caption = "Revise/Send Order"
Else
Me.cmdEditPO.Caption = "Revise this Order"
End If
'check if a filter is applied and highlight the filter button if it is
If Me.FilterOn = True Then
Me.cmdApplyFilter.BackColor = vbYellow
Else
Me.cmdApplyFilter.BackThemeColorIndex = 4
Me.cmdApplyFilter.BackShade = 40
Me.cmdApplyFilter.Gradient = 12
End If
'refresh the subform
DoCmd.Requery "PO Details"
It also appears that you are setting the txtUser, txtName, txtUnit and txtUserSecurity to the same values in every case, so rather than declaring them multiple times like this, you can just set them as the default values for your controls on the navigation form itself. You can declare the TempLoginID as a TempVar so that is available to you throughout your database, and that then lets you put the dlookups for the other data anywhere you need them, or lets you set the data for the form to include the User table so you can access them directly without needing dlookup.
Hope that helps a little!

Login form with permissions in access

I've making a simple database with a login form.
I have a tblAccessLevel with AccessLevelID (autonumber) and Accless Level, with a relation to the User Table "tblUsers"
When a new user is added you can select the access level they need.
I;m trying to add a rule so when opening certain forms, it looks at the user logged in and see if they have the correct access level then either allow or deny them.
this is the code i have in place:
UserView = DLookup("AccessLevel", "tblUsers", "[curUser] = " & [AccessLevel])
If UserView = "1" Then
Me.Command0.Enabled = True
Else: UserView = "3" Or "2"
Me.Command0.Enabled = False
End If
The curUser is defined in the login form:
curUser = DLookup("Username", "tblUsers", "[Username]=""" & Me.txtUsername.Value & """")
Kind Regards,
Ashley
Main_Form
Private Sub Form_Load()
Set dbLog = CurrentDb
Set LogRec = dbLog.OpenRecordset("tblLog")
LogRec.AddNew
LogRec("eDate").Value = Date
LogRec("eTime") = Format(Now, "Long Time")
LogRec("Form").Value = "Main Form"
LogRec("User").Value = curUser
LogRec("Detail").Value = curUser & " Opened Main Form"
LogRec.Update
UserView = DLookup("AccessLevel", "tblUsers", "[curUser] = " & [AccessLevel])
If UserView = 1 Then
Me.Command0.Enabled = True
Else
Me.Command0.Enabled = False
End If
End Sub
Form_Login (Login command with code)
Public Sub cmdLogin_Click()
Dim dbLog As DAO.Database
Dim LogRec As DAO.Recordset
'Check to see if data is entered into the Username Field
If IsNull(Me.txtUsername) Or Me.txtUsername = "" Then
MsgBox "You must enter a Username.", vbOKOnly, "Required Data"
Me.txtUsername.SetFocus
Exit Sub
End If
'Check to see if data is entered into the password box
If IsNull(Me.txtPassword) Or Me.txtPassword = "" Then
MsgBox "You must enter a Password.", vbOKOnly, "Required Data"
Me.txtPassword.SetFocus
Exit Sub
End If
'Check value of password in tblEmplyees to see if this matched value chosen in Username Field
If Me.txtPassword.Value = DLookup("Password", "tblUsers", "[Username]=""" & Me.txtUsername.Value & """") Then
curUser = DLookup("Username", "tblUsers", "[Username]=""" & Me.txtUsername.Value & """")
Set dbLog = CurrentDb
Set LogRec = dbLog.OpenRecordset("tblLog")
LogRec.AddNew
LogRec("eDate").Value = Date
LogRec("eTime") = Format(Now, "Long Time")
LogRec("Form").Value = "Login"
LogRec("User").Value = curUser
LogRec("Detail").Value = "User " & curUser & " Logged in"
LogRec.Update
MyEmpID = Me.txtUsername.Value
'Close Logon form and open splash screen
DoCmd.Close acForm, "frmLogin", acSaveNo
DoCmd.OpenForm "MainForm"
Else
Set dbLog = CurrentDb
Set LogRec = dbLog.OpenRecordset("tblLog")
LogRec.AddNew
LogRec("eDate").Value = Date
LogRec("eTime") = Format(Now, "Long Time")
LogRec("Form").Value = "Login"
LogRec("User").Value = "N/A"
LogRec("Detail").Value = "Someone tried to access your database with an invalid password"
LogRec.Update
MsgBox "Password invalid. Please try again", vbCritical + vbOKOnly, "Invalid Entry!"
Me.txtPassword.SetFocus
End If
'If User Enters incorrect password 3 times database will shutdown
intLogonAttempts = intLogonAttempts + 1
If inLogonAttempts > 3 Then
MsgBox "You do not have access to this database. Please contact your system administrator.", vbCritical, "Restricted Access!"
Application.Quit
End If
End Sub
Private Sub Form_Load()
Set dbLog = CurrentDb
Set LogRec = dbLog.OpenRecordset("tblLog")
LogRec.AddNew
LogRec("eDate").Value = Date
LogRec("eTime") = Format(Now, "Long Time")
LogRec("Form").Value = "Login"
LogRec("User").Value = "N/A"
LogRec("Detail").Value = "Someone logged into your database"
LogRec.Update
End Sub
ModCurUser
Option Compare Database
Public curUser As Variant
ModUserView
Option Compare Database
Public UserView As Variant
The error is appearing on:
UserView = DLookup("AccessLevel", "tblUsers", "[curUser] = " & [AccessLevel])
On the assumption 'curUser' is a Global Variable, available to all VBA modules, you could also make 'UserView' a GV. Then, yes, you could have your 'Switchboard' command buttons enabled or disabled based on 'UserView' . If you worry about creative people simply opening a form manually, then you could add code to your forms like:
Private Sub Form_Load()
If UserView = 1 Then
' no action necessary - allow access
Else
MsgBox "You do not have permission to use this form"
DoCmd.Close acForm, Me.Name
End If
End Sub
A couple other observations you may be interested in:
Variable 'intLogonAttempts' needs to be defined at the Form level - not inside the subroutine. If not, it will never count the attempts correctly (will always be 1).
WHen you load the Login form, you say 'N/A' is attempting to log in. It may be better to track the user-login name or workstation name i.e. Environ$("Username") or Environ("computername")
When comparing the password for validation, some applications may want to force a 100% comparision. Currently your test doesn't force users to match the CASE of the password. The following is a simple solution:
If Len(Me.txtPassword.value) = Len(<from your Dlookup>) Then
For i = 1 To Len(<from your Dlookup>)
If Asc(Mid$(Me.txtPassword.value, i, 1)) <> Asc(Mid$(<from your Dlookup>, i, 1)) Then
blnWrongPWD = True
End If
Next i
Else
blnWrongPWD = True
End If
Good Luck, Wayne

Using query yes/no field for checkbox record source?

First of all, you start with a form named LoginF. Once you choose your login ID, and password; and log in it takes data from the table LoginIntoT for the login ID you chose, and creates a query with said data using this code:
On Error Resume Next
DoCmd.DeleteObject acQuery, "IsAdminQ"
On Error GoTo Err_LoginBtn_Click
Dim qdef As DAO.QueryDef
Set qdef = CurrentDb.CreateQueryDef("IsAdminQ", _
"SELECT IsAdmin " & _
"FROM LoginInfoT " & _
"WHERE EmployeeID = " & LoginCmBx.Value)
Exit_LoginBtn_Click:
DoCmd.Close acForm, "LoginF", acSaveNo
DoCmd.OpenForm "MenuF"
Exit Sub
Err_LoginBtn_Click:
MsgBox Err.Description
Resume Exit_LoginBtn_Click
From there in that query after you log in is only 1 column and 1 row; meaning one piece of data. This data is a yes/no field which is either Yes or No depending on who you logged in as.
On the form it opens after you click the login button it has a logout button. The logout button brings you to the previous login form, and deletes the query (IsAdminQ).
What I am trying to do is attach a yes/no button on a form to take that data, and output if it's yes or no on the query.
I've tried putting this in it's control source:
=[IsAdminQ].[IsAdmin]
Though what that does is output it as a filled in square instead of a checkmark or empty. I have triple state set as no.
How would I attach the checkbox to the query so if the data says yes, then it's a check mark and if it says no it is an empty box?
I understand you.
"On the form it opens after you click the login button it has a logout button", we call it frmLogout. You shall do this:
Solution I:
frmLogout.RecordSource = "IsAdminQ"
Then for your checkbox named MyCheckbox, we set it this:
Me.MyCheckbox.ControlSource = "IsAdmin"
You cannot use this:
Me.MyCheckbox.ControlSource = "[IsAdminQ].[IsAdmin]" ' <= here it's impossible.
Solution II:
On the form frmLogout without setting IsAdminQ as .RecordSource,
In a Public Module, insert this:
Function GetLoginStateIsAdmin()
'
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordSet("IsAdminQ")
GetLoginStateIsAdmin = Nz(rst(0), False)
Set rst = Nothing
'
End Function
Then in the private module of any form, as frmLogout:
Private Sub Form_Open(Cancel As Integer)
'
Me.MyCheckbox.Value = GetLoginStateIsAdmin()
'
End Sub
Set it in addition in design mode:
Me.MyCheckbox.TripleState = false
And check also if the query IsAdminQ has been successfully created in the login step. And open it in Access Navigation Pane by double-clicking on it. And see the value of the query.

Resources