title: MS Access 2016 - Check access level on Openform using Tempvars
body: <p>My intent is to deny users that do not meet a certain access level access to forms. I initially had issues with error code 3265 while writing the code for:</p>
  
  <p><code>TempVars("EmployeeType").Value = rs!EmployeeType_ID.Value</code></p>
  
  <p>This is no longer an issue; however, I cannot get access to the form even when the appropriate user is trying to enter. I've checked the spelling of table and column names multiple times as well. </p>
  
  <p>Below is my code for the login (where I'm using the tempvars), followed by the code in form Load().</p>
  
  <pre><code>Option Compare Database
  Option Explicit
  
  Private Sub btnLogin_Click()
  Dim rs As Recordset
  
  Set rs = CurrentDb.OpenRecordset("Employees", dbOpenSnapshot, dbReadOnly)
  
  rs.FindFirst "UserName='" &amp; Me.txtUserName &amp; "'"
  
  If rs.NoMatch = True Then
      Me.lblWrongUser.Visible = True
      Me.txtUserName.SetFocus
      Exit Sub
  End If
  Me.lblWrongUser.Visible = False
  
  If rs!Password &lt;&gt; Me.txtPassword Then
      Me.lblWrongPass.Visible = True
      Me.txtPassword.SetFocus
      Exit Sub
  End If
  
  If IsNull(Me.txtUserName) Or IsNull(Me.txtPassword) Then
      MsgBox "You must enter password or login ID.", vbOKOnly + vbInformation, "Required Data"
      Me.txtUserName.SetFocus
      Exit Sub
  End If
  Me.lblWrongPass.Visible = False
  
  If rs!EmployeeType &gt;= 4 Then
      Dim prop As Property
      On Error GoTo SetProperty
      Set prop = CurrentDb.CreateProperty("AllowBypassKey", dbBoolean, False)
  
      TempVars("UserName").Value = Me.txtUserName.Value
      TempVars("EmployeeType").Value = rs!EmployeeType_ID.Value
  
      CurrentDb.Properties.Append prop
  
  SetProperty:
      If MsgBox("Would you like to turn on the bypass key?", vbYesNo, "Allow Bypass") = vbYes Then
          CurrentDb.Properties("AllowBypassKey") = True
      Else
          CurrentDb.Properties("AllowBypassKey") = False
      End If
  
  End If
  
  Me.Visible = False
  DoCmd.OpenForm "frmMain"
  
  Globals.LoggingSignOn "Logon"
  
  End Sub
  
  Private Sub Form_Load()
  Me.txtUserName = Null
  Me.txtPassword = Null
  Me.txtUserName.SetFocus
  End Sub
  
  Private Sub Form_Unload(Cancel As Integer)
  Globals.LoggingSignOn "Logoff"
  End Sub
  
  Private Sub Form_Load()
      If Nz(DLookup("HasAccess", "tbl9EmployeeAccess", "EmployeeType_ID=" &amp; TempVars("EmployeeType") &amp; " FormName='" &amp; Me.Name &amp; "'"), False) = False Then
          MsgBox "You do not have access to access this location."
          DoCmd.Close acForm, Me.Name
      End If
  End Sub
  </code></pre>
  
  <p>Thank you for your time, to anybody that looks into this.</p>