Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close an active ODBC connection
I've got a connection to a SQL database that I create when I update the
source data. I keep it open to run multiple queries from the same source but I want to close it when I close the workbook. How can I close an active connection that was created and maintained in a different sub-routine? |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close an active ODBC connection
How are you keeping it opened? Is ther are Public or Static variable that
you are using? If ther is a variable associated with the connection then simply create a workbook close event, close the conection variable, and then set the Connection variable to equal nothing. "Jeff" wrote: I've got a connection to a SQL database that I create when I update the source data. I keep it open to run multiple queries from the same source but I want to close it when I close the workbook. How can I close an active connection that was created and maintained in a different sub-routine? |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close an active ODBC connection
I have a subroutine that creates the connection. The connection can take a
little bit to open (I'm assuming it's a network thing) so I don't want to keep opening and closing it. That's why I thought it would be easier to open it once and close it when I'm done with it. The programmer does it this way through Visual Basic for the same reasons. "Joel" wrote: How are you keeping it opened? Is ther are Public or Static variable that you are using? If ther is a variable associated with the connection then simply create a workbook close event, close the conection variable, and then set the Connection variable to equal nothing. "Jeff" wrote: I've got a connection to a SQL database that I create when I update the source data. I keep it open to run multiple queries from the same source but I want to close it when I close the workbook. How can I close an active connection that was created and maintained in a different sub-routine? |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close an active ODBC connection
Are you sure you are keeping the connection open after the macro finishes?
VBA doesn't normally retain connections when a macro ends. That is why I'm asking? If it is automatically closing when the macro finishes, then you don't need to close it again. You'll just get an error. "Jeff" wrote: I have a subroutine that creates the connection. The connection can take a little bit to open (I'm assuming it's a network thing) so I don't want to keep opening and closing it. That's why I thought it would be easier to open it once and close it when I'm done with it. The programmer does it this way through Visual Basic for the same reasons. "Joel" wrote: How are you keeping it opened? Is ther are Public or Static variable that you are using? If ther is a variable associated with the connection then simply create a workbook close event, close the conection variable, and then set the Connection variable to equal nothing. "Jeff" wrote: I've got a connection to a SQL database that I create when I update the source data. I keep it open to run multiple queries from the same source but I want to close it when I close the workbook. How can I close an active connection that was created and maintained in a different sub-routine? |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Close an active ODBC connection
I got it working and the connection speed isn't prohibitive so I don't need
to solve this problem. Thanks anyway. Jeff "Joel" wrote: Are you sure you are keeping the connection open after the macro finishes? VBA doesn't normally retain connections when a macro ends. That is why I'm asking? If it is automatically closing when the macro finishes, then you don't need to close it again. You'll just get an error. "Jeff" wrote: I have a subroutine that creates the connection. The connection can take a little bit to open (I'm assuming it's a network thing) so I don't want to keep opening and closing it. That's why I thought it would be easier to open it once and close it when I'm done with it. The programmer does it this way through Visual Basic for the same reasons. "Joel" wrote: How are you keeping it opened? Is ther are Public or Static variable that you are using? If ther is a variable associated with the connection then simply create a workbook close event, close the conection variable, and then set the Connection variable to equal nothing. "Jeff" wrote: I've got a connection to a SQL database that I create when I update the source data. I keep it open to run multiple queries from the same source but I want to close it when I close the workbook. How can I close an active connection that was created and maintained in a different sub-routine? |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
SQL ODBC Connection | Excel Programming | |||
SQL ODBC Connection | Excel Programming | |||
ODBC Connection | Excel Programming | |||
ODBC Connection | Excel Programming | |||
ODBC connection by udl | Excel Programming |