How can we create an object (edit box, checkbox) at run time ??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • overcomer
    New Member
    • Nov 2008
    • 25

    How can we create an object (edit box, checkbox) at run time ??

    Hi,

    This is related to Code Behind AutoForm question that I've posted yesterdat but no one replies to that.

    What i want a solution for is I need to have a flexible page1 whereas the field/objects (fields from a certain table that were added/created dynamically in a separate page2) could be created in the page1 at run time (using VB code). I'm using MS Access 2003 in Windows XP environment.

    I've tried the Load funciton but it's not working as the object does not have an index property in MS Access.

    Your comments/suggestions will be a big help.

    Thanks.

    Regards,
    Cindy
  • FishVal
    Recognized Expert Specialist
    • Jun 2007
    • 2656

    #2
    Hello, Cindy.

    You may use CreateControl() method.
    Keep in mind that form where control is being created has to be opened in design view and be not the form where CreateControl() method is being executed.
    Below is a simple example.

    [code=vb]
    Private Sub Command0_Click( )

    Dim strName As String

    strName = "Form2"
    DoCmd.OpenForm strName, acDesign
    CreateControl strName, acTextBox, acDetail, , , 100, 100, 2000, 250
    DoCmd.OpenForm strName, acNormal, , , , acWindowNormal

    End Sub
    [/code]

    As an alternative you may design form with a sufficient fixed number of controls and change their visibility as required.

    Regards,
    Fish

    Comment

    • overcomer
      New Member
      • Nov 2008
      • 25

      #3
      Thank you so much Fish... it is really a big help...

      Comment

      Working...