Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change a Microsoft Access form view from Single Form to Continous Forms at Runtime?

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?

like image 324
Haris Ghauri Avatar asked Oct 16 '25 10:10

Haris Ghauri


1 Answers

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
like image 143
random_answer_guy Avatar answered Oct 18 '25 04:10

random_answer_guy