Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Parents and looping

I have a loop that worked just fine unitl I changed my userform and therefore
had to change the code. The problem with the loop is that I want it to go
through every control in two different frames. I do not know how to write
this. Thus the erronous line is:

For Each ctl In Me.StartDatumRam1.Controls & in Me.StartDatumRam2.Controls

The first part until the "&" is correct I just dont know how to write it for
two frames. please help me out! Thanks very much!

The complete loop
Private Sub startDatumTextBoxSub()
Dim i As Long
Dim ctl As Control
ReDim strStartDatumArray(0 To lngNumberOfCheckBoxes)
For Each ctl In Me.StartDatumRam1.Controls & in
Me.StartDatumRam2.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Parents and looping

Is there any reason you can't simply use two loops?


Dim ctl As Control
For Each ctl In Me.StartDataRam1.Controls
' do something
Next ctl
For Each ctl In Me.StartDataRam2.Control
' do something
Next ctl


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Viktor Ygdorff" wrote
in message
...
I have a loop that worked just fine unitl I changed my userform
and therefore
had to change the code. The problem with the loop is that I
want it to go
through every control in two different frames. I do not know
how to write
this. Thus the erronous line is:

For Each ctl In Me.StartDatumRam1.Controls & in
Me.StartDatumRam2.Controls

The first part until the "&" is correct I just dont know how to
write it for
two frames. please help me out! Thanks very much!

The complete loop
Private Sub startDatumTextBoxSub()
Dim i As Long
Dim ctl As Control
ReDim strStartDatumArray(0 To lngNumberOfCheckBoxes)
For Each ctl In Me.StartDatumRam1.Controls & in
Me.StartDatumRam2.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 703
Default Parents and looping

I think you'll have to use two separate loops

ReDim strStartDatumArray(0 To lngNumberOfCheckBoxes)

For Each ctl In Me.StartDatumRam1.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl

For Each ctl In Me.StartDatumRam2.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl


"Viktor Ygdorff" wrote:

I have a loop that worked just fine unitl I changed my userform and therefore
had to change the code. The problem with the loop is that I want it to go
through every control in two different frames. I do not know how to write
this. Thus the erronous line is:

For Each ctl In Me.StartDatumRam1.Controls & in Me.StartDatumRam2.Controls

The first part until the "&" is correct I just dont know how to write it for
two frames. please help me out! Thanks very much!

The complete loop
Private Sub startDatumTextBoxSub()
Dim i As Long
Dim ctl As Control
ReDim strStartDatumArray(0 To lngNumberOfCheckBoxes)
For Each ctl In Me.StartDatumRam1.Controls & in
Me.StartDatumRam2.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Parents and looping

thanks for quick answer. yes i know i can use two loops but i have quite a
few loops and it doubles the code length. but you are right. plus it bugs me
that i cannot figure it out. In short I can use two loops but it is far from
desirable. thanks. Do you (or anyone else) know how to write the code so that
it only requires one loop? I would very much appreciate any help!

"Chip Pearson" skrev:

Is there any reason you can't simply use two loops?


Dim ctl As Control
For Each ctl In Me.StartDataRam1.Controls
' do something
Next ctl
For Each ctl In Me.StartDataRam2.Control
' do something
Next ctl


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Viktor Ygdorff" wrote
in message
...
I have a loop that worked just fine unitl I changed my userform
and therefore
had to change the code. The problem with the loop is that I
want it to go
through every control in two different frames. I do not know
how to write
this. Thus the erronous line is:

For Each ctl In Me.StartDatumRam1.Controls & in
Me.StartDatumRam2.Controls

The first part until the "&" is correct I just dont know how to
write it for
two frames. please help me out! Thanks very much!

The complete loop
Private Sub startDatumTextBoxSub()
Dim i As Long
Dim ctl As Control
ReDim strStartDatumArray(0 To lngNumberOfCheckBoxes)
For Each ctl In Me.StartDatumRam1.Controls & in
Me.StartDatumRam2.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Parents and looping

is it really so? I mean to mean it seems like there would be no problem with
one loop altough I am no expert.

"Charlie" skrev:

I think you'll have to use two separate loops

ReDim strStartDatumArray(0 To lngNumberOfCheckBoxes)

For Each ctl In Me.StartDatumRam1.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl

For Each ctl In Me.StartDatumRam2.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl


"Viktor Ygdorff" wrote:

I have a loop that worked just fine unitl I changed my userform and therefore
had to change the code. The problem with the loop is that I want it to go
through every control in two different frames. I do not know how to write
this. Thus the erronous line is:

For Each ctl In Me.StartDatumRam1.Controls & in Me.StartDatumRam2.Controls

The first part until the "&" is correct I just dont know how to write it for
two frames. please help me out! Thanks very much!

The complete loop
Private Sub startDatumTextBoxSub()
Dim i As Long
Dim ctl As Control
ReDim strStartDatumArray(0 To lngNumberOfCheckBoxes)
For Each ctl In Me.StartDatumRam1.Controls & in
Me.StartDatumRam2.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl
End Sub



  #6   Report Post  
Posted to microsoft.public.excel.programming
JMB JMB is offline
external usenet poster
 
Posts: 2,062
Default Parents and looping

Maybe you could use an array to store your frames, then loop through the array.
Something similar to

Sub test()
Dim varFrames As Variant
Dim cntl As Control
Dim t As Long

varFrames = Array(Me.StartDatumRam1, _
Me.StartDatumRam2)

For t = LBound(varFrames) To UBound(varFrames)
For Each cntl In varFrames(t).Controls
MsgBox cntl.Name
Next cntl
Next t

End Sub

"Viktor Ygdorff" wrote:

thanks for quick answer. yes i know i can use two loops but i have quite a
few loops and it doubles the code length. but you are right. plus it bugs me
that i cannot figure it out. In short I can use two loops but it is far from
desirable. thanks. Do you (or anyone else) know how to write the code so that
it only requires one loop? I would very much appreciate any help!

"Chip Pearson" skrev:

Is there any reason you can't simply use two loops?


Dim ctl As Control
For Each ctl In Me.StartDataRam1.Controls
' do something
Next ctl
For Each ctl In Me.StartDataRam2.Control
' do something
Next ctl


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com





"Viktor Ygdorff" wrote
in message
...
I have a loop that worked just fine unitl I changed my userform
and therefore
had to change the code. The problem with the loop is that I
want it to go
through every control in two different frames. I do not know
how to write
this. Thus the erronous line is:

For Each ctl In Me.StartDatumRam1.Controls & in
Me.StartDatumRam2.Controls

The first part until the "&" is correct I just dont know how to
write it for
two frames. please help me out! Thanks very much!

The complete loop
Private Sub startDatumTextBoxSub()
Dim i As Long
Dim ctl As Control
ReDim strStartDatumArray(0 To lngNumberOfCheckBoxes)
For Each ctl In Me.StartDatumRam1.Controls & in
Me.StartDatumRam2.Controls
If TypeName(ctl) = "TextBox" Then
strStartDatumArray(i) = ctl.Value
i = i + 1
End If
Next ctl
End 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
Looping David T Excel Discussion (Misc queries) 2 August 30th 06 10:51 PM
Looping Buffyslay Excel Programming 1 February 1st 06 05:57 PM
Help with looping dok112[_55_] Excel Programming 0 November 1st 05 05:09 PM
Grab Parents? Kidaz Excel Programming 1 October 21st 05 07:04 PM
Looping Louise[_4_] Excel Programming 1 September 10th 04 04:57 PM


All times are GMT +1. The time now is 11:34 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"