Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Dim CTL as MSForms.Control always sets as Control/Combobox

In the following code, I would like to be able to dim a listbox variable,
lboBox, and
then insert the following after the first loop line:
For Each CTL In frmSettings.Controls

If TypeOf CTL Is MSForms.ListBox Then
set lboBox = CTL
Elseif Typeof CTL is MSForms.Combobox then
set cboBox = CTL
end if

I can't figure out seems always (from the very beginning) Dimmed as a
combobox control, and therefore skips the first IF Then line EVEN when the
control is a ListBox.


Any thoughts would be greatly appreciated.


My problem code:

Private Sub InitializeIndicators(frmSettings As MSForms.UserForm)
On Error GoTo InitializeIndicators_Err

Dim cboBox As MSForms.ComboBox
Dim strboxName As String
Dim i As Integer
Dim CTL As MSForms.Control

For Each CTL In frmSettings.Controls
If TypeOf CTL Is MSForms.ComboBox Then
If InStr(1, LCase(CTL.Name), LCase("lboIndicator")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboIndicator"), 0)
ElseIf InStr(1, LCase(CTL.Name), LCase("lboPeriod")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboPeriod"), 0)
ElseIf InStr(1, LCase(CTL.Name), LCase("lboOperator")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboOperatorLeft"), 0)
ElseIf InStr(1, LCase(CTL.Name), LCase("lboOperator")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboOperatorRight"), 1)
End If
End If
Next

Set cboBox = Nothing
Exit Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Dim CTL as MSForms.Control always sets as Control/Combobox

Not 100% sure what you are after, as you mix terms: The function FillListBox
has arguments of cboBox and lboIndicator.

But something like this ?

Dim WorkingBox As MSForms.Control
Dim strboxName As String
Dim i As Integer
Dim CTL As MSForms.Control

For Each CTL In frmSettings.Controls
If (TypeOf CTL Is MSForms.ComboBox) Or (TypeOf CTL Is
MSForms.ListBox) Then
Set WorkingBox=CTL
Call FillListBox(WorkingBox, ListRows("lboIndicator"), 0)

NickHK

"Post Tenebras Lux" wrote in
message ...
In the following code, I would like to be able to dim a listbox variable,
lboBox, and
then insert the following after the first loop line:
For Each CTL In frmSettings.Controls

If TypeOf CTL Is MSForms.ListBox Then
set lboBox = CTL
Elseif Typeof CTL is MSForms.Combobox then
set cboBox = CTL
end if

I can't figure out seems always (from the very beginning) Dimmed as a
combobox control, and therefore skips the first IF Then line EVEN when the
control is a ListBox.


Any thoughts would be greatly appreciated.


My problem code:

Private Sub InitializeIndicators(frmSettings As MSForms.UserForm)
On Error GoTo InitializeIndicators_Err

Dim cboBox As MSForms.ComboBox
Dim strboxName As String
Dim i As Integer
Dim CTL As MSForms.Control

For Each CTL In frmSettings.Controls
If TypeOf CTL Is MSForms.ComboBox Then
If InStr(1, LCase(CTL.Name), LCase("lboIndicator")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboIndicator"), 0)
ElseIf InStr(1, LCase(CTL.Name), LCase("lboPeriod")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboPeriod"), 0)
ElseIf InStr(1, LCase(CTL.Name), LCase("lboOperator")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboOperatorLeft"), 0)
ElseIf InStr(1, LCase(CTL.Name), LCase("lboOperator")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboOperatorRight"), 1)
End If
End If
Next

Set cboBox = Nothing
Exit Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 41
Default Dim CTL as MSForms.Control always sets as Control/Combobox

Thanks. I think I worked it out. I also didn't realize that
ListRows("lboIndicator") is a function that returns a list (from an array)
that fills the combo or list box. The "lboIndicator" is used in an Instr
function to choose which set of data to put in the array. There are other
"OtherStrings" that return the same array, but filled with different data.

I don't really know what was wrong, but when I rebuilt the function
elsewhere in the code it worked fine. Same code. Go figure.

Appreciate the suggestion.


"NickHK" wrote:

Not 100% sure what you are after, as you mix terms: The function FillListBox
has arguments of cboBox and lboIndicator.

But something like this ?

Dim WorkingBox As MSForms.Control
Dim strboxName As String
Dim i As Integer
Dim CTL As MSForms.Control

For Each CTL In frmSettings.Controls
If (TypeOf CTL Is MSForms.ComboBox) Or (TypeOf CTL Is
MSForms.ListBox) Then
Set WorkingBox=CTL
Call FillListBox(WorkingBox, ListRows("lboIndicator"), 0)

NickHK

"Post Tenebras Lux" wrote in
message ...
In the following code, I would like to be able to dim a listbox variable,
lboBox, and
then insert the following after the first loop line:
For Each CTL In frmSettings.Controls

If TypeOf CTL Is MSForms.ListBox Then
set lboBox = CTL
Elseif Typeof CTL is MSForms.Combobox then
set cboBox = CTL
end if

I can't figure out seems always (from the very beginning) Dimmed as a
combobox control, and therefore skips the first IF Then line EVEN when the
control is a ListBox.


Any thoughts would be greatly appreciated.


My problem code:

Private Sub InitializeIndicators(frmSettings As MSForms.UserForm)
On Error GoTo InitializeIndicators_Err

Dim cboBox As MSForms.ComboBox
Dim strboxName As String
Dim i As Integer
Dim CTL As MSForms.Control

For Each CTL In frmSettings.Controls
If TypeOf CTL Is MSForms.ComboBox Then
If InStr(1, LCase(CTL.Name), LCase("lboIndicator")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboIndicator"), 0)
ElseIf InStr(1, LCase(CTL.Name), LCase("lboPeriod")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboPeriod"), 0)
ElseIf InStr(1, LCase(CTL.Name), LCase("lboOperator")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboOperatorLeft"), 0)
ElseIf InStr(1, LCase(CTL.Name), LCase("lboOperator")) Then
Set cboBox = CTL
Call FillListBox(cboBox, ListRows("lboOperatorRight"), 1)
End If
End If
Next

Set cboBox = Nothing
Exit Sub




Reply
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
form control combobox Gail Excel Discussion (Misc queries) 7 October 2nd 09 07:27 PM
Control ToolBox ComboBox Steve D Excel Discussion (Misc queries) 1 July 1st 09 05:17 PM
Using Multiple sets of Option Buttons (Form Control) In Excell Michael Hudston Excel Worksheet Functions 2 February 26th 09 08:07 AM
Excel Combobox Box Control [email protected] Excel Programming 2 April 10th 06 07:48 AM
MsForms.Control Event Class AikonEnohp via OfficeKB.com Excel Programming 3 September 19th 05 01:03 AM


All times are GMT +1. The time now is 05:46 PM.

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"