Change database connection

G

Gary Watson

I have 3 SQL Server databases with the same schema. I've created an Access
ADP to connect to one of them and a simple application to look at the various
table. BY manually editing the connection (by FILE | Connection and editing
the server properties) I can connect to each of the databases and run my
application.

I would like to be able to add a button to a form to allow me to select
which database to use. I've tried using CurrentProject.Connection to change
the connection string but this does not seem to work (The
CurrentProject.CloseConnection falis).
Any ideas on how to do this?
Thanks
Gary
 
D

David Lloyd

Gary:

I was able to use the following code to change the database connection.

Function ChangeDatabase()
Dim sConnect As String

sConnect = CurrentProject.BaseConnectionString

sConnect = Replace(sConnect, "CurrentDatabaseName", "NewDatabaseName")

CurrentProject.CloseConnection

CurrentProject.OpenConnection (sConnect)

End Function

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I have 3 SQL Server databases with the same schema. I've created an Access
ADP to connect to one of them and a simple application to look at the
various
table. BY manually editing the connection (by FILE | Connection and editing
the server properties) I can connect to each of the databases and run my
application.

I would like to be able to add a button to a form to allow me to select
which database to use. I've tried using CurrentProject.Connection to change
the connection string but this does not seem to work (The
CurrentProject.CloseConnection falis).
Any ideas on how to do this?
Thanks
Gary
 
G

Gary Watson

The CloseConnection fails with an error 6008.
MSDN suggests retrying the close connection, which seems to work, except the
openconnection then fails.
 
Top