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


Board Regular
Oct 25, 2006
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.

Forum statistics

Latest member

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...