VBA for Error Handling

rhmkrmi

Active Member
Joined
Aug 17, 2012
Messages
341
Office Version
  1. 365
Platform
  1. Windows
Hi there,

Do you know how I can use Error Handling in VBA to create a pop-up message for the end user when the connection cannot be refreshed due to disconnection from the database?

The error that Excel produces is like: [DataSource.Error] ODBC: ERROR [HY000] and so on.

Thank you.
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Does it give you an error number?
If so, then it is easy to capture it in error handling.
 
Upvote 0
Yes, it gives me error codes IM006 and HY000 in the same message.

Thank you.
 
Upvote 0
Hmmm... those aren't typical error codes.
Do you get this error when you run VBA code, or sometime else?
If it is when you run the VBA code, can you post the code?
 
Upvote 0
I am running an SQL and I get this message when the refresh fails because there is no connection to the database.
I am using ODBC and run a query in SQL to dynamically refresh values in Excel.
 
Upvote 0
So, you aren't running any VBA when this error occurs?
You typically add error handling code to VBA code where the error occurs.
If the error is not happening due any VBA code running, then there is nothing to add error handling to.

If you can check the connection via VBA code, then perhaps you could add code to the Workbook_Open event (which runs when the workbook is first opened), to check to see if the connection works. If you can come up with the VBA code to check the connection, we can help add error handling to that code.
 
Upvote 0

Forum statistics

Threads
1,215,831
Messages
6,127,138
Members
449,361
Latest member
VBquery757

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top