Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Loop thru the controls contained in a SSTAB

Status
Not open for further replies.

vietnam97

Programmer
Sep 18, 2000
48
0
0
I have a SSTAB control with 3 tabs, if I want to loop thru all the controls contained in a particular tab, say tab1, then how would I do this?

I've tried the following code and it gave me an error saying "Error 438: Object doesn't support this property or method"

For Each Ctl In MyForm.SSTab1
With MyForm.SSTab1
...Load values of controls into database
End With
Next


Thanks,
Bao

 
Try this...
[tt]
For Each Ctl In MyForm
If Ctl.Container = MyForm.SSTab1 _
And Ctl = TextBox Then
With rs
!Name = Ctl.Text
...Load values of controls into database
End With
End If
Next
[/tt] Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
Thanks Craig.

What wrong with my code? I thought SSTab1 is the container and by pointing to MyForm.SSTab1, I just have to use the For Each to loop thru the controls contained within...
 
Could be. I've enver done it that way. Hwere is the code dying.. Which line. Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
With my version of code or yours... Craig, mailto:sander@cogeco.ca

Remember not to name the Lambs...
It only makes the chops harder to swallow
 
Some controls do not have containers e.g. Timer.
You can not use = to compare objects. You must use IS.
Dim ctl As Control
Dim cont as Object ' Container could be form not a control
For Each Ctl In MyForm
On Error Resume Next
Set cont = ctl.Container
if err.Number <> 0 then Set cont = Nothing
On Error goto 0
If cont IS MyForm.SSTab1 Then
If Ctl IS TextBox Then
With rs
!Name = Ctl.Text
...Load values of controls into database
End With
End If
End if
Next
Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
My question above pertain to my code.

However when I tried your code out, it died on the line
If Ctl.Container = MyForm.SSTab1 then
(note that I removed to second part of the If)

with the error code:

Error 450: Wrong number of arguments or invalid property assignment
 
You may also need to check the .Tab property of the Tab Container is you need to know on which tab the controls that you are interested in

If cont IS MyForm.SSTab1 Then
if cont.tab = <desired tab> then
If Ctl IS TextBox Then

Note: tabs are zero based - the first tab has a .tab value of 0 Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
The basic problem with your code as initially posted is that
is assumes that the tab has its own collection of controls. It does not. Only the Form has the Controls Collection.
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
If you are interested just in Textboxes you can do this:

Dim Ctl as Control
For Each Ctl in Controls
If Typeof Ctl Is TextBox Then
If Ctl.Container Is SSTAB1 Then
...........................
...........................
End If
End If
Next
 
Hi John,

I used your code and changed the If statement a little.Basically I tried to get all the controls on tab1 but somehow the code missed it. I step thru a few controls on tab1 and checked the tab number (cont.tab) and it showed the tab = 0 instead.

For Each Ctl In MyForm
On Error Resume Next
Set cont = ctl.Container
if err.Number <> 0 then Set cont = Nothing
On Error goto 0
If cont IS MyForm.SSTab1 Then
If TypeOf Ctl is TextBox and cont.tab = 1 then
With rs
!Name = Ctl.Text
...Load values of controls into db
End With
End If
End if
Next


 
Hi All,

Basically, from what I have tried, when iterate through the control collection, we can tell if the control is contained in the SSTab, but we don't know on which tab number that control belongs to, to be able to do something with it.

Thanks,
Bao
 
Try checking the Visible=True for the textbox, Left or top as minus values or > Width or Height. I remeber reading somewhre that the &quot;unseen&quot; controls were moved &quot;offstage&quot; by f...ooling with the position. I can't try it now. Generate Forms/Controls Resizing/Tabbing Class
Compare Code (Text)
Generate Sort Class in VB or VBScript
 
Vietnam, you have it correct by looking at the .Tab property. You must remember that tabs are numbered, starting with zero.

The first tab will have a .Tab = 0,
The Second tab has a .Tab = 1.
The Third tab as a .Tab = 2.

and so forth


Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
So why not place a frame on each tab and check if the control's container name is a certain frame - I do this all the time......When looping through all controls on a form I do not check to see if the container is a sstab, but if the container is a frame and depending on the frames name and/or index, (prefer using an array of frames for a SSTab - frame with index 0 is on Tab 0 and so forth), I take the needed action.
All controls for a certain Tab are one one frame placed on that tab.
 
Thank you all for your helpful suggestions.

John: I had to make the desired tab active before looping thru all the controls, and then check for the property Left >0 on each control. This way I'll be able to collect only the visible controls on my desired tab and it worked as expected.

CajunCenturon: Even though I know the set of textboxes that I want belongs to tab 1, but the current active tab is 0, so without setting the sstab1.tab = 1 prior to looping thru all the controls and then check for the property Left>0 on each, there is no way i could collect the set of textboxes on tab1

CCLINT: The Frame approach is easier to understand, since I can directly pick the set of controls that I want based on the desired Frame container and it should be unique.

Again, thanks all for your helps.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top