View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jim Thomlinson Jim Thomlinson is offline
external usenet poster
 
Posts: 5,939
Default Type MisMatch with Set Statement

First off start declaring your variables and add option explicit to your
code. It will make situations like this a lot easier to deal with. Your code
is doing a lot of on the fly declarations using inappropriate names. For
example you are on the fly declaring a variant called Control which is a bad
idea since Control is a reserved word. Check out this link for info on
declaring variables...

http://www.cpearson.com/excel/variables.htm

Now on to your specific problem... Controls is a collection object that
holds all of the controls contained in a specific object. For example code
something like this will work on your userform (me gives you a reference to
the userform)...

dim ctl as control

for each ctl in me.controls
msgbox ctl.name
next ctl

Your line of code however
Controls(Array("tbxBallasts", "cboBallasts", "cboLamps1", ...
is looking in an unspecified collection of controls for an array of text
values. What you really want is to create your own collection of controls to
loop through... to that end try something like this...

dim colFlorescent as collection

set colFlorescent = new collection
with colFlorescent
..add tbxBallasts
..add cboBallasts
end with

now you can do something like
dim ctl as control

for each ctl in colFlorescent
msgbox ctl.name
next ctl

--
HTH...

Jim Thomlinson


"RyanH" wrote:

I am getting a 'Type Mismatch Error' when I use the Set Statement in a
control of my Userform. I want to change the Enabled and BackColor
properties of certain Controls on the Userform when the Illumination ComboBox
equals certain values. I have an Array of all the Controls Names. Why am I
getting this error?

Private Sub cboIllumination_Change()

Set Fluorescents = Controls(Array("tbxBallasts", "cboBallasts",
"cboLamps1", _
"cboLamps2", "tbxLamps1",
"tbxLamps2", _
"cboOrientation1", "cboOrientation2"))

Set LEDs = Controls(Array("tbxTransformers", "cboSpacing", "tbxLEDs"))

Select Case cboIllumination

Case "Single Row T12 HO Fluorescent"
For Each Control In Fluorescents
Control.BackColor = vbWindowBackground
Next Control
For Each Control In frmLEDs.Controls
Control.Enabled = False
Next Control
For Each Control In LEDs
Control.BackColor = vbButtonFace
Next Control

Case "Single Row T8 HO Fluorescent"
For Each Control In Fluorescents
Control.BackColor = vbWindowBackground
Next Control
For Each Control In frmLEDs.Controls
Control.Enabled = False
Next Control
For Each Control In LEDs
Control.BackColor = vbButtonFace
Next Control

Case "LEDs"
For Each Control In LEDs
Control.BackColor = vbWindowBackground
Next Control
For Each Control In frmFluorescents.Controls
Control.Enabled = False
Next Control
For Each Control In Fluorescents
Control.BackColor = vbButtonFace
Next Control

End Select

'disables Estimate command button if no illumination, and visa versa
If cboIllumination = "No Illumination" Then
cmbEstimate.Enabled = False
Else
cmbEstimate.Enabled = True
End If

End Sub

Thanks in Advance,
Ryan