dynamically add check boxes to a form

mattcdse

Registered User.
Local time
Today, 06:01
Joined
Nov 23, 2005
Messages
42
Hi all, :)

Is it possible to add check boxes (or any controls for that matter) hen a form loads. Bassically I need people to select which items will require a change on a change request form (or could a list box do this?)

As the number of items available can change I need the correct number of boxes to appear on the form. I could just add them all, but as we change the items available, I'd have to change the form to suit. Something I'm not reallly willing to do.
Anyy ideas folks? :)

Cheers,

Matt
 
It's very complex to do as you have to open the form in design view programatically and then add the controls and then save the form, and then reopen in form view. The easiest method is to add all the controls to the form first, leave them hidden and make them visible (and move them around) at run time.
 
Thanks Bob,

The idea is a good one :) , but as I said, I didn't really want to change the form everytime I had to add or remove a specific item as I'd have to add the check box, change the code to show/hide it and to save the new records.

I had a quick look at the list box properties and methods. The methods ItemsSelcted and ItemData came to the rescue. The code below works a treat :cool: by finding selected items in a list box and adding the data to a new record. This is a sample, my actual code fills more fields in the record.

For Each varItem In Me.lstBox.ItemsSelected
With rs
.AddNew
!Code = Me.lstBox.ItemData(varItem)
.Update
End With

Thanks for the suggestion,

Cheers,

Matt
 
Just for future reference, you can add multiple controls on a form and just name them in numbered form (chk1, chk2, chk3, etc.) and then you can actually assign the bound field to them at run time, so it is possible to dynamically set them, it's just a bear to try to actually create them at run time.
 

Users who are viewing this thread

Back
Top Bottom