简体   繁体   中英

Run time error 9 : subscript out of range while retrieving data from SQL Server database

I get this error very often, trying to figure out a solution for this.

The statement that gets highlighted when this error message observed is

With ActiveWorkbook.Connections("US**** PIRExposure_G2_4 tConrac"). _
        OLEDBConnection

Please let me know if I need to post my entire VBA code here. I am trying to import a row from a SQL Server database into Excel by running a pre-recorded macro after deleting the range of cells where previously executed macro result is displayed.

I have finally found that this was due to the lack of connection that exists or gets deleted when I was trying to clear the range where the result is displayed prior.

How did I debug ?

Checked if connection exists or not by going to Ribbon - Data - Connection and check if the connection exists there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM