Excel VBA code doesn't get all the data (from an online SQL database) when run in certain laptops

Viewed 37

I have this VBA code to get certain data from an online sql server (using mysql odbc):

If CN.State = 0 Then    
    DBConnection
End If

RS.Open "SELECT SUM(timesheet_details.hours_spent), SUM(timesheet_details.hours_spent_overtime), timesheets.id, timesheets.date, timesheets.user_id 

FROM timesheets RIGHT JOIN timesheet_details ON timesheets.id = timesheet_details.timesheet_id

GROUP BY timesheets.id", CN, adOpenKeyset

iRows = 2

While Not RS.EOF    
    For iCols = 0 To RS.Fields.Count - 1        
        Sheets("Timesheets Source").Cells(iRows, iCols + 2).Value = RS.Fields(iCols).Value    
    Next    
    RS.MoveNext    
    iRows = iRows + 1
Wend

RS.Close

Say it is supposed to generate 3000 rows of data. The problem is when this code is run in some laptops, it doesn't generate all 3000 rows (for example, only 1000 rows instead). Here is what I found so far about this error:

  1. The 1000 data that it generates is always the same in every run and in any laptop.
  2. From the 1000 data, there seems to be no pattern why the code generates them and not the other 2000.
  3. I have tried laptop with different specs and with different Excel version but didn't manage to find any pattern why only some laptops have this issue.
  4. This error applies for all kind of SQL query.

Does anyone have any idea how to resolve this problem?

0 Answers
Related