title: VBA Code for Conditional Visibility
body: <p>Im currently working on a form in MS Access 2013 and have a button to switch between two data modes, Read Only and Edit. I have a label saying "Edit Mode" and Im trying to display it only when the data mode is Edit. With that in mind, and the fact that Im extremely new to coding/programming as a whole, here is my code behind the button:</p>
  
  <pre><code>If Me.AllowEdits = True Then
      DoCmd.close acForm, "frmStudents"
      DoCmd.OpenForm "frmStudents", acNormal, "", "", acReadOnly, acNormal
      Me.txtBox.Visible = False
  
  ElseIf Me.AllowEdits = False Then
      DoCmd.close acForm, "frmStudents"
      DoCmd.OpenForm "frmStudents", acNormal, "", "", acFormEdit, acNormal
      Me.txtBox.Visible = True
  
  End If
  </code></pre>
  
  <p>I keep getting an error saying that the object is closed or doesnt exist when I use the button.</p>
  
  <p>Any help is much appreciated.</p>