Switch SQL Connections

T

tredd68

What is the best way to connect to different SQL Server Databases from a form
in Access 2007? I have a server with multiple databases. I want my users to
be able to click on a button from a form to switch the connection from
database to another.
 
S

Sylvain Lafontaine

For an ADP project or for a MDB or ACCDB database file with ODBC Linked
tables? For an ADP project, I would say to use the
CurrentProject.CloseConnection and CurrentProject.OpenConnection method.
Instead of trying to discover each available servers and database on the
network, you could store the address of the server in a table in each
accessible database (or locally in the VBA code or in properties) for an
easy display.

--
Sylvain Lafontaine, ing.
MVP - Windows Live Platform
Email: sylvain2009 sylvainlafontaine com (fill the blanks, no spam please)
Independent consultant and remote programming for Access and SQL-Server
(French)
 
T

tredd68 via AccessMonster.com

Thanks, I will give it a shot.

Sylvain said:
For an ADP project or for a MDB or ACCDB database file with ODBC Linked
tables? For an ADP project, I would say to use the
CurrentProject.CloseConnection and CurrentProject.OpenConnection method.
Instead of trying to discover each available servers and database on the
network, you could store the address of the server in a table in each
accessible database (or locally in the VBA code or in properties) for an
easy display.
 
V

Vadim Rapp

Hello,

t> What is the best way to connect to different SQL Server Databases from a
t> form in Access 2007? I have a server with multiple databases. I want my
t> users to be able to click on a button from a form to switch the
t> connection from database to another.

If this is the same server, then you can use the same connection, no need to
switch anything. Dynamically concatenate the sql string and then specify it
as recordsource etc. Like this:

dbname = inputbox("enter db name:")
me.recordsource = "select * from " & dbname & "..table where ...... "


Regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top