Adding Form Objects Programmatically

illy2k

Registered User.
Local time
Today, 09:13
Joined
Apr 21, 2003
Messages
51
Is there anyway that you can add lets say a textbox to a form with VBA, or can you only have it as visible = false then set it visible = true?
 
My understanding is that there is no way to do it on a currently opened form. You can do it on a form in design view. The following code creates a form and then adds a commandbutton. I threw this together quickly while figuring it out... HTH

Code:
    Dim f As Form
    Set f = CreateForm
    With f
      .AutoResize = True
      .AutoCenter = True
      .Caption = "My Form"
      .CloseButton = True
      .MinMaxButtons = False
      .PopUp = True
      ' and whatever other props you want to set
    End With
    Dim b As CommandButton
    Set b = CreateControl(f.Name, acCommandButton, acDetail)
    With b
      .Width = 2440
      .Height = 500
      .Visible = True
      .Caption = "my button"
      ' and whatever other props you want
    End With
    DoCmd.OpenForm f.Name, acNormal, , , , acDialog
 
You can programmatically open an existing form in design view, keep it hidden, add or change elements, save changes, and then open the form for business.
Code:
   DoCmd.OpenForm strAnyForm, acDesign, , , , acHidden
   With Forms(strAnyForm)
[COLOR=Green]      'do changes here[/COLOR]
   End With
   DoCmd.Close acForm, strAnyForm, acSaveYes
[COLOR=Green]   'now open modifed item[/COLOR]
   DoCmd.OpenForm strAnyForm
If you don't make a ton of changes you can execute this seemelessly without the user noticing a delay.
 

Users who are viewing this thread

Back
Top Bottom