List command buttons in a form

P

pcb_svp

Hi,

I have a lot of command buttons within a form and in the future there
could even be more.
The name of this command button needs to be created dynamically.
I could to this with relative easy by manually programming something
in VBA for every command button.

However it would be a lot more efficient if i could dynamically create
a list of the the command buttons of the form.
And then for each element get the name.

Does anyone know how you can get a list of all command buttons from a
form within VBA?
 
D

Daniel Pineault

You can use the following to loop through all the control of your form

Dim ctl as Control

For Each ctl in Me.Controls
if ctl.ControlType = acCommandButton then
'Do your thing here
End if
Next ctl

set ctl=nothing

Take a look at 'ControlType Property' in the help file it has a good example
to go from.
 
P

pcb_svp

You can use the following to loop through all the control of your form

Dim ctl as Control

For Each ctl in Me.Controls
   if ctl.ControlType = acCommandButton then
        'Do your thing here
   End if
Next ctl

set ctl=nothing

Take a look at 'ControlType Property' in the help file it has a good example
to go from.
--
Hope this helps,

Daniel Pineault
If this post was helpful, please rate it by using the vote buttons.








- Tekst uit oorspronkelijk bericht weergeven -

Thanks, that was very hepful.
Just one last question: how do you get a reference to a control with a
certain name?
I have a string that represents the name of a control but I don't know
how I can acccess the control directly by using the string?

Many thanks
 

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