juanchoelx
juanchoelx

Reputation: 387

VBA Access: Create a new button in a 2010 Access form

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

Answers (1)

rmh
rmh

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

Related Questions