Run-Time Error '3704': Operation is not allowed when the object is closed

elbartje

New Member
Joined
Oct 28, 2015
Messages
39
I got a problem:

I want to connect to a data bank.
If the connection fails or I get an error
I use this:

Code:
On error goto close_databank

close_databank:
close connection

Now when this hapens and he jumps to close_databank then I get a new error:
Run-Time Error '3704':
Operation is not allowed when the object is closed

How can I say when error 3704 don't close connection
Or check if connection if open if true then close else nothing ?
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Use an IF statement to check the specific error number. If it's closed - then you don't try closing it. Assuming 3704 is the error for closed

If err.number = 3704 then
'already closed
else
close connection
end if
 
Upvote 0

Forum statistics

Threads
1,216,844
Messages
6,133,038
Members
449,775
Latest member
richardd85

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