Reputation: 387
I am trying to create a new button on a form Access 2010. If I click on a button to create a new button on the form, but I can not create the button if the form view is different from the design view (Error 6062: You must be in Design or Layout View to create or delete controls). How I can create the button with VBA code? Thanks.
Private Sub Command2_Click()
Dim boton As CommandButton
Set boton = CreateControl(Me.Name, acCommandButton, acFooter)
With newButton
.Visible = True
.Enabled = True
.Caption = "prueba"
End With
End Sub
Upvotes: 0
Views: 349
Reputation: 77
There is a much easier way to accomplish what you want. You can create the button on the form add make Visible = False on the property sheet. Then your code would just be:
Private Sub Command2_Click()
Me.Command3.Visible = True
End Sub
Then when you click the button it would make the button appear on the form. What are you trying to accomplish by creating the command button? Is there a reason this method is insufficient?
Upvotes: 1