-
May 13th, 2004, 01:55 PM
#1
Thread Starter
Fanatic Member
Adding controls to SSTab at runtime [resolved]
hello;
I just finished perusing search results from this forum, but could not find the answer to the following and I suspect I am S.O.L. on this one....I want to add controls (checkboxes) dynamically to an SSTab control at run-time....the problem is this: I am also creating the sstab at runtime as I do not know how many tabs will be required. This is an admin tool to hide/show fields from a db (Access) where I want checkboxes for each field, and a tab for each table. So adding frames in this case does not resolve the problem. code is as follows:
VB Code:
'this is how I create the sstab:
Private Sub createTabs(ByVal mCon As ADODB.Connection)
Dim rs As ADODB.Recordset
Set rs = db.getAllTables(mCon)
Dim i As Integer
Dim maxWidth As Integer
i = 0
Set sTab = Me.Controls.Add("TabDlg.SSTab", "Tab1", Me)
sTab.Font = Me.Font
With sTab
.Left = 100
.Height = Me.Height - cmdSave.Height - 1000
.Top = 100
If rs.RecordCount <= 11 Then
.TabsPerRow = rs.RecordCount - 1
Else
.TabsPerRow = (rs.RecordCount - 1) / 2 + 1
End If
.Tabs = rs.RecordCount - 1
Do While Not rs.EOF
If rs.Fields("TABLE_NAME").Value <> "tblOptions" Then
.TabCaption(i) = rs.Fields("TABLE_NAME").Value
End If
If maxWidth < TextWidth(rs.Fields("TABLE_NAME").Value) Then
maxWidth = TextWidth(rs.Fields("TABLE_NAME").Value)
End If
i = i + 1
rs.MoveNext
Loop
.TabMaxWidth = maxWidth + 250
Me.Width = .Width + 300
.Visible = True
End With
Set rs = Nothing
End Sub
'and this is my attempt to populate each tab with checkboxes
Private Sub populateTabs(ByVal mCon As ADODB.Connection)
Dim rs As ADODB.Recordset
Dim iTab As Integer
Dim iRowCounter As Integer
Dim chkBox As CheckBox
Dim theLeft As Integer
Dim theTop As Integer
theLeft = 100
theTop = 500
For iTab = 0 To sTab.Tabs - 1
sTab.Tab = iTab
Set rs = db.getRecordSet("select field_name, show_field, is_key from tblOptions " _
& "where table_name='" & sTab.TabCaption(iTab) & "'", mCon)
Do While Not rs.EOF
Set chkBox = Me.Controls.Add("VB.Checkbox", "CheckBox" & iCheckBox, sTab)
With chkBox
.Width = 2000
.Height = 375
.Left = theLeft
.Top = theTop
.Caption = rs.Fields("field_name").Value
.Value = rs.Fields("show_field").Value
.Enabled = CBool(rs.Fields("is_key").Value)
.Visible = True
End With
Set chkBox.Container = sTab
iRowCounter = iRowCounter + 1
iCheckBox = iCheckBox + 1
iTab = iTab + 1
If iRowCounter Mod 10 = 0 Then
theTop = 100
theLeft = theLeft + 2100
Else
theTop = theTop + 450
End If
rs.MoveNext
Loop
Next iTab
Set rs = Nothing
End Sub
NOTE: in case of wondering, the db code is valid - it's all wrapped in an ADO class I made.
All controls are getting added to the first tab....am I screwed????
thanks
Last edited by ahara; May 13th, 2004 at 03:26 PM.
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
-
May 13th, 2004, 02:08 PM
#2
-
May 13th, 2004, 02:12 PM
#3
Thread Starter
Fanatic Member
Originally posted by Mc Brain
First of all, you don't need to create the SStab at runtime. You can modify the number of tabs the same way you're doing it.
actually, I do need to do it at runtime...this is for an app that different clients will use...I am trying to create one module that will suit all users' needs so that coding is minimized.
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
-
May 13th, 2004, 02:16 PM
#4
Need-a-life Member
-
May 13th, 2004, 02:21 PM
#5
-
May 13th, 2004, 03:25 PM
#6
Thread Starter
Fanatic Member
thanks a lot for the examples Mc Brain....it led me to the solution in the end......I noticed that your example was working, and mine was not....pasted your code into my project - again it failed.....after some time (and a few highly descriptive curses), I finally got it to work by moving the code from form_load to form_activate....don't ask me why this makes a difference - I'm just grateful to have it working. Thanks a bunch!!
"Knowledge is gained when different people look at the same information in different ways"
- Louis Pasteur
-
May 13th, 2004, 03:31 PM
#7
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|