Automatically increase checkboxes depending on data

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shaiful
    New Member
    • Oct 2007
    • 89

    Automatically increase checkboxes depending on data

    Hi all,
    I have a problem with checkbox. I have a database where i will get specific rows depending on user input, I dont know how many rows will select. I need to display rows on user end and which will appear with beside checkboc where user can select their desire rows. My problem is how to increase checkbox and how mention their name? I have no idea about increasing check box depend on loop, I mean such as,

    dim Rs as Recordset
    Con.open"select Name from Emp where sal>2000"
    Do Until Rs.EOF

    I want to show checkbox here , autometically appear on Form
    Rs.MoveNext
    Loop
    Thx advance my all friends, Shaiful
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Why don't you use listbox instead.

    But if you want to still use checkbox ,create one at designtime as control array and use count to findout the number of records.
    Create the checkboxes by increasing the index at runtime and add the data to the caption of the checkbox control

    Comment

    • shaileshb
      New Member
      • Jun 2007
      • 27

      #3
      Hi,

      You can go for a control array.
      For ex.

      Steps

      1. Place one checkbox control on your form
      2. Give appropriate name to your checkbox control - chkBox

      To work with control array you need to set index property of control
      3. Set index property to Zero (0)
      4. Find total no. of rows retrieved from your table. For ex. RecCount = 10 rows
      5. Use loop
      [code=vb]For i = 0 To RecCount
      If i = 0 Then
      chkBox(i).Capti on = rs!FieldName
      Else
      Load chkBox(i)
      chkBox(i).Top = (chkBox(i-1).Top + chkBox(i-1).Height) + 20
      chkBox(i).Capti on = rs!FieldName
      chkBox(i).Visib le = True
      End If
      Next[/code]

      Note : Before creating new CheckBox at runtime check for the existence of the checkbox, if it is then remove first then again recreate.
      To unload:
      Unload chkBox(i)

      You can not unload the control created at design time i.e. chkBox(0)
      Last edited by Killer42; Dec 24 '07, 10:49 PM.

      Comment

      • Ali Rizwan
        Banned
        Contributor
        • Aug 2007
        • 931

        #4
        Originally posted by shaiful
        I have a problem with checkbox ...
        Use the code provided but I think create all the checkboxes at runtime neither in design time.
        I mean one you will create in design not here but create it also in runtime.
        Using the way I have told you on Yahoo!.
        Else if you have also an error in this code mail me.

        Regards.

        >> ALI <<
        Last edited by Killer42; Dec 24 '07, 10:51 PM.

        Comment

        • shaiful
          New Member
          • Oct 2007
          • 89

          #5
          Hi, its work great in vb6. Actually i am working with VBA in there no index property i can set, in that case how i solve this problem? Thx again.

          Comment

          Working...