'Use a TempVars to reference a control on a sub form from another form

I have a form with a subform for data entry. The subform uses a combobox to populate a field. If the value needed is not in the combobox a command button opens another form (CollaboratorEnter) where values can be added. Once the new value is added I close (CollaboratorEnter) and set the new value in the combobox on the subform to the value added. The code for this is:

Forms![frm2ProjectEnter].Form.[sfmProjectCollab].form.cboCollaboratorID = Me.CollaboratorID

I call the form (CollaboratorEnter) from various forms and subforms throughout my application. What I would like to do is use TempVars to store the names of the various forms and subforms and use them in the statement above. I've managed to use TempVars for the main form name, but can't get it to work for the subform name. I know it has to do with controls vs forms, but I can't get the right syntax. I've set variables as Forms, Controls, and Strings, but have been unsuccessful.

This question is similar to one asked 10 years ago. "Can I use a variable as the name of a control in Microsoft Access VBA"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source