I am writing a program which involves a few Groupboxes and a sub-routine to manipulate the controls in each of the groupboxes (e.g. add buttons, remove controls) according the variables given e.g. GroupBA, GroupBD....etc.
However, I received "NullReferenceException" unless I write the hardcode to specify the exact name of Groupbox like Me.GroupBA.Controls.clear() to action.
Is there any way to handle those groupbox in an array to avoid any repeated code?
e.g. ClearAllControls(GroupBA)
Sub ClearAllControls (WorkGP)
Me.GroupBA.Controls.Clear() 'The code only works if targeted the "GroupBA"
Me.Controls(WorkGP).Controls.Clear() 'Resulted Error NullReferenceException
Me.Controls("GroupBA").Controls.Clear() 'Resulted Error NullReferenceException
End