LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
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

 
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
Type Mismatch: array or user defined type expected ExcelMonkey Excel Programming 4 July 6th 06 03:40 PM
Type mismatch using rnge as Range with Type 8 Input Box STEVE BELL Excel Programming 11 December 3rd 05 05:02 AM
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
Case when statement gives type mismatch Henrik[_6_] Excel Programming 2 June 16th 04 04:36 PM
Type mismatch while running If statement Stel Excel Programming 4 December 18th 03 09:19 AM


All times are GMT +1. The time now is 04:34 AM.

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

About Us

"It's about Microsoft Excel"