I am working on an old VB6 application. Clearly no maintenance was held and the most of the code is placed in one form which has like 5000 lines. This is makes quite hard to find bugs.

I can see that the DataGrid is the main part of the form and the code contains some logic for locking/unlocking and hiding/hiding columns when a certain condition is met.

This data grid is connected to a predefined ADODC(placed on the same form) component which uses string query to load data from a table.

Also when this form loads there are additional two queries that should fill the ADODC component on form load.
I found that at some case the ADODC is with zero rows since the query doesn't find any data for the given case, but logic for locking/unlocking and hiding/hiding is still executed even there are no data to display in the DataGrid.
This causes application failure with error

Code:
"datagrid runtime error "6160" Data Access Error"
I tried to add some validation with the ADODC component like:

Code:
if MyAdodc.Recordset.RecordCount > 0 then
     ' do left over application stuff
else
     Exit sub
end if
This however ended with another DataGrid control error:

Code:
 The current row is not available.
Is there something I should follow when using DataGrid and ADODC or this is simply a bad programming and badly designed flow of control?