Excel Vba handling errors from Ado Connections/permissions to SQL server.

robtyketto

Board Regular
Joined
Oct 25, 2006
Messages
108
Hi All,

My spreadsheet is a front-end for users to execute queries/store procs against SQL server databases and output the rowset(s) to worksheets, this is all working well.

It's the error handling I want to improve, currently my error handling consists of the usual "On error" and displays the vba Error Number and description, which works well in displaying a suitable message when the server is unavailable or an invalid Server or database has been specified in the connection string, the problem I want to specifically capture is if the user doesn't have permission to the database (trusted connection/windows credential based in the connection string).

I've printed both the excel and the ado error details, but if a users don't have permission to a database it's attempting to run a command against it appears to bypass the "On error" error handling and a message box appears displaying the error icon and just the text "5" (from memory) rather than the full details I've specified.

Has anyone experience of specifically capturing/checking error codes related to SQL permissions?
I did read that Excel vba can't capture some Ado errors but found nothing concrete.
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

Watch MrExcel Video

Forum statistics

Threads
1,099,794
Messages
5,470,825
Members
406,727
Latest member
Kimze

This Week's Hot Topics

Top