-->

How do you dynamically create controls on a MS Acc

2020-07-24 15:24发布

问题:

I am writing a survey (data input) form in MS Access. I need to dynamically display all the questions in the questions table in labels on my form. Each of these question labels will also be accompanied by a combo box that will display possible answers.

How can I add labels to a form dynamically?

回答1:

See the CreateControl Method. For a label, use acLabel from the AcControlType Enumeration as the ControlType parameter for CreateControl.

However, this will get more complicated. In addition to creating the label control you will want to set its caption, position (Top and Left properties), and size (Width and Height properties). Perhaps other properties as well: Font Name; Font Size; Font Weight; etc.

It could be easier to structure your data source so it contains a row for each question and answer pair. Then present those rows in a continuous form with 2 controls: a text box for the question; and the combo box for the answer. Then you wouldn't need to bother with creating controls dynamically.