LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Passing Control Names in an Array to another Procedure

I have a UserForm with about 15 Checkboxes, each representing a Department.
By each Department CheckBox I have 4 other controls: DTPicker, Checkbox,
Textbox, and Textbox. I have set all 4 Controls Visible property to False at
Design Time. Here is the code that I have for 1 of the 15 Department
Checkboxes:

Private Sub chkFoamRouter_Click()

' show or hide dept information controls
dtpFoamRouter.Visible = chkFoamRouter
chkFoamRouterDone.Visible = chkFoamRouter
tbxFoamRouterEstHrs.Visible = chkFoamRouter
tbxFoamRouterActHrs.Visible = chkFoamRouter

' enable or disable dept information controls
Call chkFoamRouterDone_Click
Me.Repaint

End Sub

Private Sub chkFoamRouterDone_Click()

' enable or disable dept information controls
dtpFoamRouter.Enabled = Not chkFoamRouterDone
chkFoamRouter.Enabled = Not chkFoamRouterDone
tbxFoamRouterEstHrs.Enabled = Not chkFoamRouterDone
tbxFoamRouterActHrs.Enabled = Not chkFoamRouterDone

End Sub

I have to do this 14 more times! I figured maybe it would be more efficient
and make the workbook file size less if I did it this way:

Private Sub chkFoamRouter_Click()

Call ControlEnabler(Array("dtpFoamRouter", "chkFoamRouterDone", _
"FoamRouterEstHrs", "FoamRouterActHrs"),
chkFoamRouter.Value)

End Sub

Private Sub chkFoamRouter_Click()

Call ControlVisible(Array("dtpFoamRouter", "chkFoamRouterDone", _
"FoamRouterEstHrs", "FoamRouterActHrs"),
chkFoamRouter.Value)

End Sub

Private Sub ControlVisible(ByVal ControlNames As Variant, ByVal vl As Boolean)

Dim i As Long

For i = 0 To 3
ERROR Controls(ControlNames(i)).Visible = vl
Next i

End Sub

Private Sub ControlEnabler(ByVal ControlNames As Variant, ByVal vl As Boolean)

Dim i As Long

For i = 0 To 3
Controls(ControlNames(i)).Enabled = Not vl
Next i

End Sub

This way I could just pass each of my 4 Controls that are next to each
department to a single procedure ControlVisible() and ControlEnabler().

Is this possible? I am getting an error indicated above; "Subscript out of
Range"
--
Cheers,
Ryan
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing sheet names to an array ExcelMonkey Excel Programming 3 March 23rd 06 10:07 AM
Passing an array or recordset to a stored procedure Paul Robinson Excel Programming 1 December 2nd 04 05:15 AM
Passing an array or recordset to a stored procedure Robin Hammond[_2_] Excel Programming 1 December 2nd 04 05:15 AM
Passing an array or recordset to a stored procedure Jamie Collins Excel Programming 1 December 2nd 04 05:15 AM
Passing properties to a procedure Matt McQueen[_2_] Excel Programming 1 July 30th 03 04:44 PM


All times are GMT +1. The time now is 06:40 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"