views:

125

answers:

2

I am creating a dynamic form in Access 2003. Each time the form is opened combo boxes are created based on table of "keywords." My code is having trouble deleting old boxes (or their labels, I'm not sure) and every opening after the first gets hung up on duplicate names (Run-time error '2450').

Secondly, junction table holding the "checked" keywords will fills up at a low finite amount.

Thirdly, I can't figure out how to populate the combo boxes based on the junction table records. When the form is loaded the boxes are always unchecked.

Thanks for any help!

A: 

Do you explicitly destroy the created controls when you close the form? I'm not sure how Access handles stuff like this, but in Delphi when you create a control and put it on a form (all in code) the control is not destroyed when the form is destroyed. For that to work, you must set the owner property of the new control to the form. Maybe Access has a similar possibility?

birger
The controls are updated when the form is loaded. First the old ones are deleted, then all the new ones are created based on a "keywords" table. To get the controls to update the junction table they cannot be bound to the form (because this form is bound to another table)
Eric D. Johnson
Access forms ARE NOT Delphi forms, so the way Delphi works has nothing to do with it. Controls added at runtime increment the counter for maximum number of controls addable to the form during the form's total lifetime, not just the current instance. THIS IS THE WAY ACCESS WORKS, and it's way dynamically adding controls is a bad idea. In addition, as Tony says, it won't work in an MDE, because design changes are not allowed in an MDE at all.
David-W-Fenton
+1  A: 

I'd suggest using a continuous subform bound to a junction table with one record per keyword and main record. The kwyword would be a combo box. Ensure you have a "dupe check" index based on both the foriegn main record key and the foriegn keyword key on the junction table.

Tony Toews
I believe I have my junction table set up as you describe, it stores one keyword ID and one main record ID per junction record. However, the junction table will not store more records than the Keyword table. Why is this and how do I fix it? Also, what makes a subform continuous? Thanks for the help!
Eric D. Johnson
Change the forms Default View to Continuous Forms. Move the labels to the header and move the controls so they run horizontally. Or create a new form using the wizard but make it tabulur.
Tony Toews
What message are you getting when you are unable to add records. I suspect you have a foreign key specified as being no duplicates allowed in the index.
Tony Toews
The junction table is updating fine now, it was a small glich with my SQL statement. Thanks for the help on the "continuous forms," I forgot their name. As a side note, when I add a control with CreateControl() it is added on the uppermost layer and not associated with anything else on the form. Is it possble to add the control to a tab without using a subform?
Eric D. Johnson