Cannot Add Subform on at Runtime

  • Thread starter Thread starter Deleted member 73419
  • Start date Start date
D

Deleted member 73419

Guest
I'm trying to add controls to a form at runtime as I will need to make some small dynamic changes to the form once loaded so I'm starting with trying to add a subform before moving on to other controls.

So far, I have this short sub:
Code:
Private Sub Form_Open(Cancel As Integer)

    Dim ctlSub1 As SubForm
        
    Call DoCmd.RunCommand(acCmdLayoutView)
    
    Set ctlSub1 = CreateControl(Forms("compa").Name, acSubform, , Forms("subform").Name, , 20, 20, 50, 100)

    Call DoCmd.RunCommand(acCmdFormView)

End Sub

When I open the host form, I get the following error:

Run-time error '29054'
Microsoft Access can't add, rename, or delete the control(s) you requested

I'm not sure why it cannot add the form - it exists as does the subform.

Has anyone come across this before?

Thanks
 
Hi. When using the Runtime environment, design changes are not allowed/possible. I am guessing CreateControl is considered to be making a design change; therefore, it is being blocked.

One workaround, depending on your situation, is to add all the controls you think you will need on a form and simply show and hide them or change their properties at run time.

PS. I was assuming you were using the above code with the Access Runtime Version. If so, does your code run fine using the full version of Access?
 
I'm trying to add controls to a form at runtime as I will need to make some small dynamic changes to the form once loaded so I'm starting with trying to add a subform before moving on to other controls
Creating objects at runtime is a horrible idea and a pretty much guaranteed way to corrupt a database. Also cannot be done in a runtime version or accde. IMO if you have to create objects at runtime your database or UI is likely poorly designed. For what reason do you need dynamic controls?
You can show, hide, move, format controls though.
 
I'm not sure why it cannot add the form - it exists as does the subform.
i think, you just cannot.
add the subform in Design view and just change it's SourceObject.
 
I'm joining in with the others. Whether this is .ACCDR, .ACCDE, or .ACCDB, it is a horrible idea. Among other things, you will run into a limit after a while because there is a limit of how many controls you can put in a section, something on the order of just under 770. However, if you can predict all of the controls, you just create them ALL and selectively disable them, make them invisible, and lock them. Then when you need to do something with a special control, just find it and enable it, unhide it,and unlock it.
 
Piling on.
Additionally, users should be using a copy of a common SHARED FE database. Therefore, UserA changing a form affects only HIS version of the application. If the users all open the same copy of the FE, then it is even worse because the change affects ALL other users if they are all sharing the same FE which is yet another terrible idea and will lead to corruption issues.

YOU are the developer. Only YOU can make design changes PERIOD. Any other scenario is the road to perdition.
 

Users who are viewing this thread

Back
Top Bottom