Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / February 2005

Tip: Looking for answers? Try searching our database.

how to create multiple controls at userform load  such as textbox.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Herve cadieu - 26 Feb 2005 09:55 GMT
In vb programs there are often controls arrays
such as command1(0),command1(1), command1(2)

and some code which reacts to specific index:

sub command1_click(index as integer)
if index =1 then
do something
else
do something else
end if
end sub

Ok I am looking for the way to create such controls array in VBA, to use
these kind of VB code in VBA projects .

I have tried to name a control command1(0) but it is not a valid name
how can I proceed to create these command(n) controls ?

Thank you for your knowledge
best regards
Howard Kaikow - 26 Feb 2005 10:48 GMT
VBA does not support control arrays.

Signature

http://www.standards.com/; See Howard Kaikow's web site.

>
> In vb programs there are often controls arrays
[quoted text clipped - 18 lines]
> Thank you for your knowledge
> best regards
Helmut Weber - 26 Feb 2005 13:37 GMT
Hi Herve,
this is an example for a workaraound
for creating arrays of controls, here for checkboxes:

Private Sub UserForm_Initialize()
' Count Optionbuttons
Dim oCnt As Control
Dim iCnt As Integer
For Each oCnt In Me.Controls
  If TypeOf oCnt Is MSForms.OptionButton Then
     iOpt = iOpt + 1
  End If
Next
' create array of optionbuttons
ReDim ArrOpt(iOpt) As OptionButton
' assign each optionbutton
For Each oCnt In Me.Controls
  If TypeOf oCnt Is MSForms.OptionButton Then
     iCnt = iCnt + 1
     Set ArrOpt(iCnt) = oCnt
    ' setting caption for testing
     ArrOpt(iCnt).Caption = Format(iCnt, "Opt- 00")
  End If
Next
End Sub

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/

Note, that the "for each loop" over all controls,
seemably, processes them in the order they were created.

Greetings from Bavaria, Germany

Helmut Weber, MVP
"red.sys" & chr(64) & "t-online.de"
Word XP, Win 98
http://word.mvps.org/
Helmut Weber - 26 Feb 2005 13:53 GMT
<gr>
... example for optionsbuttons ...
of course

HW
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.