By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,642 Members | 2,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,642 IT Pros & Developers. It's quick & easy.

Automatically increase checkboxes depending on data

P: 89
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"select Name from Emp where sal>2000"
Do Until Rs.EOF

I want to show checkbox here , autometically appear on Form
Thx advance my all friends, Shaiful
Dec 23 '07 #1
Share this Question
Share on Google+
4 Replies

Expert 5K+
P: 8,127
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
Dec 24 '07 #2

P: 27

You can go for a control array.
For ex.


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
Expand|Select|Wrap|Line Numbers
  1. For i = 0 To RecCount
  2.     If i = 0 Then
  3.         chkBox(i).Caption = rs!FieldName
  4.     Else
  5.         Load chkBox(i)
  6.         chkBox(i).Top = (chkBox(i-1).Top +  chkBox(i-1).Height) + 20
  7.         chkBox(i).Caption = rs!FieldName
  8.         chkBox(i).Visible = True
  9.     End If
  10. Next
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)
Dec 24 '07 #3

Ali Rizwan
P: 927
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.


>> ALI <<
Dec 24 '07 #4

P: 89
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.
Dec 26 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.