[Solved] Why is this object reference supposedly not set to an instance of an object that has obviously been identified by the compiler?


The fix ended up being simple, and even logical, in hindsight.

The controls are dynamically added to the form, like so:

formCustCatMaint.Controls.Add(coName)
And so, replacing this line, in the loop:

For Each cntrl As Control In Me.Controls
…with this:

For Each cntrl As Control In formCustCatMaint.Controls
And this line, in the GetLabelTextForID() function:

For Each cntrl As Control In Me.Controls
…with this:

For Each cntrl As Control In formCustCatMaint.Controls
…did the trick. The controls are being found, and the code is working as designed/originally expected.

Nebenbei bemerkt, this also works fine now:

If TypeOf cntrl Is CheckBox Then

solved Why is this object reference supposedly not set to an instance of an object that has obviously been identified by the compiler?