Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What event is triggered when an Excel external data range is refreshed

Status
Not open for further replies.

j9

Programmer
Jun 6, 2001
90
US
I posted this in the office forum, too...

Background info: I have several external data ranges in my excel workbook and it contains two worksheets. Each data range is automatically refreshed on file open and is associated with queries that provide data based on the user's login (e.g. select * from whatever where loginfield=suser_sname()--> suser_sname() is just a function that retrieves the login of the person on the machine).

Anyway, my problem is that a SQL Server error occurs if a user who is not allowed access to SQL Server opens my workbook. So, I would like to trap the error and kindly kick the user out. As far as I can tell, the error happens as soon as a data range tries to refresh. But, I can't seem to figure out which event is associated with this, i.e. where do I place the error-trapping code?

Much Thanks!
 
What you could try to do is run the code in the workbook manually through the VBE. Before doing so, place stops at various point through the code (click on the gray area on the left side of the code window). By doing this, you can see how far things get before the error occurs. ----------------------------------------
If you are reading this, then you have read too far... :p

lightwarrior@hotmail.com
 
There really is no code associated with the data ranges-they were all created with mouse clicks. The code I'm going to try to use to trap the SQL errors is:

set mySQLerr=application.OLEDBErrors(1)
Msgbox "The following error occurred:" & _ mySQLerr.ErrorString

BUT, I can't figure out where to place this code. For example, I tried placing it in the workbook_open() event procedure, but the code above was never executed because the data range refreshes AFTER the workbook opens.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top