Results 1 to 7 of 7

Thread: Adding controls to SSTab at runtime [resolved]

  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

  2. #2
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,810
    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.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  3. #3

    Thread Starter
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    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

  4. #4
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,810
    Second of all... hope you might found this snippet useful.
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  5. #5
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,810
    Originally posted by ahara
    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.
    I still don't understand why you need to create the SSTab at runtime, but in that case, this snippet should be more useful than the previous one.
    Attached Files Attached Files
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

  6. #6

    Thread Starter
    Fanatic Member ahara's Avatar
    Join Date
    Nov 2003
    Location
    Toronto
    Posts
    531
    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

  7. #7
    Need-a-life Member Mc Brain's Avatar
    Join Date
    Apr 2000
    Location
    Buenos Aires, Argentina
    Posts
    6,810
    Originally posted by ahara
    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!!
    I've no idea. It might be because of the visible status of the objects. In the Load event, the form, and the objects are not visible (unless you force it). Maybe, that's the reason... but, I'm just guessing.
    Emiliano F. Martín


    If a post has helped you then please Rate it! (and give the user points he/she deserves by clicking on the image).
    Encourage the person who helped you to keep doing it, and give him the points he deserves.


    MP3 Organizer: Freeware to logically organize all your MP3s.

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