How do you dynamically create controls on a MS Access form?

19,394

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.

Share:
19,394
Nick
Author by

Nick

Software developer in the Boise, Idaho area. Interests: C#, C\C++, Objective-C Client-side scripting Design architecture, Patterns

Updated on June 28, 2022

Comments

  • Nick
    Nick almost 2 years

    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?