I want to put a button in my form that changes its view with a button click. I tried putting in this subroutine:
Pricate Sub SwitchView_Click()
Me.DefaultView = 1
End Sub
But upon running it, I encountered an error that says
Run-time error '2136': To set this property, open the form or report in Design View.
How do I solve this?
First issue is that you can not display a button on the Datasheet view, so you may have to use the Dbl_Click event.
In any regard, something like this :
Private Sub SwitchView_Click()
Select Case Me.CurrentView
Case 1
'Currently in form view
DoCmd.RunCommand acCmdDesignView
Case 2
'Currently in datasheet view
DoCmd.RunCommand acCmdFormView
Case Else
'Must be design view (0) or some as yet undefined view
'So do nothing.
End Select
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With