Forgot some declarations in my question:
Dim PiBatchN As PIUnitBatch
Dim PiSubBatchArray As PISubBatches
Dim PiSubBatchN As PISubBatch
Thanks makes sense because the PiSubBatches object will never be Nothing at that point. The issues is this line:
If Not(PiSubBatchArray Is Nothing) Then
You should check if the count of the subbatches is greater than zero instead.
Sorry for the delay but I tried getting the pisubbatch info without the if statement and it still deosn't work.
I'm explaining it in here: Problem in getting subbatch information
Apologies for the messy posts.