Results 1 to 7 of 7

Thread: Adding controls to SSTab at runtime [resolved]

Threaded View

  1. #1

    Thread Starter
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531

    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:
    1. 'this is how I create the sstab:
    2. Private Sub createTabs(ByVal mCon As ADODB.Connection)
    3.     Dim rs As ADODB.Recordset
    4.     Set rs = db.getAllTables(mCon)
    5.     Dim i As Integer
    6.     Dim maxWidth As Integer
    7.     i = 0
    8.     Set sTab = Me.Controls.Add("TabDlg.SSTab", "Tab1", Me)
    9.     sTab.Font = Me.Font
    10.     With sTab
    11.         .Left = 100
    12.         .Height = Me.Height - cmdSave.Height - 1000
    13.         .Top = 100
    14.         If rs.RecordCount <= 11 Then
    15.             .TabsPerRow = rs.RecordCount - 1
    16.         Else
    17.             .TabsPerRow = (rs.RecordCount - 1) / 2 + 1
    18.         End If
    19.         .Tabs = rs.RecordCount - 1
    20.         Do While Not rs.EOF
    21.             If rs.Fields("TABLE_NAME").Value <> "tblOptions" Then
    22.                 .TabCaption(i) = rs.Fields("TABLE_NAME").Value
    23.             End If
    24.             If maxWidth < TextWidth(rs.Fields("TABLE_NAME").Value) Then
    25.                 maxWidth = TextWidth(rs.Fields("TABLE_NAME").Value)
    26.             End If
    27.             i = i + 1
    28.             rs.MoveNext
    29.         Loop
    30.         .TabMaxWidth = maxWidth + 250
    31.         Me.Width = .Width + 300
    32.         .Visible = True
    33.     End With
    34.    
    35.     Set rs = Nothing
    36. End Sub
    37. 'and this is my attempt to populate each tab with checkboxes
    38.  
    39. Private Sub populateTabs(ByVal mCon As ADODB.Connection)
    40.     Dim rs As ADODB.Recordset
    41.     Dim iTab As Integer
    42.     Dim iRowCounter As Integer
    43.     Dim chkBox As CheckBox
    44.     Dim theLeft As Integer
    45.     Dim theTop As Integer
    46.     theLeft = 100
    47.     theTop = 500
    48.    
    49.     For iTab = 0 To sTab.Tabs - 1
    50.         sTab.Tab = iTab
    51.         Set rs = db.getRecordSet("select field_name, show_field, is_key from tblOptions " _
    52.         & "where table_name='" & sTab.TabCaption(iTab) & "'", mCon)
    53.        
    54.         Do While Not rs.EOF
    55.             Set chkBox = Me.Controls.Add("VB.Checkbox", "CheckBox" & iCheckBox, sTab)
    56.             With chkBox
    57.                 .Width = 2000
    58.                 .Height = 375
    59.                 .Left = theLeft
    60.                 .Top = theTop
    61.                 .Caption = rs.Fields("field_name").Value
    62.                 .Value = rs.Fields("show_field").Value
    63.                 .Enabled = CBool(rs.Fields("is_key").Value)
    64.                 .Visible = True
    65.             End With
    66.             Set chkBox.Container = sTab
    67.             iRowCounter = iRowCounter + 1
    68.             iCheckBox = iCheckBox + 1
    69.             iTab = iTab + 1
    70.             If iRowCounter Mod 10 = 0 Then
    71.                 theTop = 100
    72.                 theLeft = theLeft + 2100
    73.             Else
    74.                 theTop = theTop + 450
    75.             End If
    76.             rs.MoveNext
    77.         Loop
    78.     Next iTab
    79.  
    80.     Set rs = Nothing
    81.  
    82. 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width