Search code examples
sql-servervbaoledboledbconnection

Refresh sheet not generating error


I have inherited a spreadsheet with a macro which isn't working from someone who's left the company.

I didn't design it, but am trying to work out why it appears to be not working (in terms of not generating the correct outputs).

I noticed that there is a section which uses an OleDb connection to run a T-SQL query and update a particular sheet, beginning with the line:

With ActiveWorkbook.Connections("Daily_Production").OLEDBConnection”

and ending with the line:

ActiveWorkbook.Connections("Daily_Production").Refresh

The thing is, there is no worksheet in the book (including in hidden sheets) called "Daily_Production". However, it does not appear to generate an error on the "refresh" line.

I'm surprised that this didn't generate an error. Surely if there is no sheet with that name, it must generate an error?

Or am I missing something? I don't have much experience with OleDb connections - is it possible that it fails to generate an error and simply doesn't bring anything through?


Solution

  • Option 1:

    The name of the connection is "Daily_Production", it's not a sheet's name. Simply write "Daily_ProductionALEALEALE" in your code and see if there is an error. If there is one, then Option 1 is correct :)

    Option 2:

    You have On Error Resume Next written somewhere.