Att PH: Adding control to form

D

Dave Neve

Hi

You kindly gave me this code about a week ago but I have not been able to
get it to work.

I have added a blank form to my doc and then I execute.

The form shows up but not with any command buttons.

Thanks in advance


Sub AddStuffToForm()


Dim ctlNew As MSForms.Control
Set ctlNew = Me.Controls.Add("Forms.CommandButton.1")

End Sub
 
P

Peter Hewett

Hi Dave Neve

It should be OK, but it does not set the controls Size, Location, Caption etc. How and
where are you calling the code from?

Cheers - Peter


Sub AddStuffToForm()


Dim ctlNew As MSForms.Control
Set ctlNew = Me.Controls.Add("Forms.CommandButton.1")

End Sub

HTH + Cheers - Peter
 
D

Dave Neve

Hi

I'm calling the code from VBA by clicking on execute.

I did wonder about size etc. Do these things have to be assigned or is there
a default?

Ta
 
P

Peter Hewett

Hi Dave Neve

Try adding the code to the Forms UserForm_Initialize event handler. If you're running the
code manually there is no persistent Form object.

HTH + Cheers - Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top