Hi SamT,

Thanks for your reply, but i didn't really get the idea of # Icon and you didn't even use it in the code you suggested. The code you suggested is exactly same as mine except that you brought Dim rs and Dim conn from my Option Explicit statement into the sub RunReport() statement, so can you eleborate on what you were trying to refer to?



Samo


Quote Originally Posted by SamT View Post
The # Icon will insert CODE Tags that you can paste the code between. You can also select the code, then use the # Icon. You can also type the CODE Tags manually.

Try this
Sub RunReport () 
    Application.ScreenUpdating=False 
    Dim rs as New ADODB RecordSet
    Dim conn As New ADODB.Connection 

    Call ConnectSqlServer 
    Call Build_SQL 

    rs.Open Sql, conn .........
'
'
'
End Sub
Row and Column Counters should always be Longs so that you don't habitually declare them as Integers when dealing with more than 32K Rows. Memory is cheap.

Variables that are only used in one Function or Sub should be declared in that Procedure.