MS Access VBA change connection string of SQL Pass Through Table

Create VBA code that will changes the connection string of the SQL Pass Through table (DB_A) to the sandbox table that gets created by DB_B
deer777Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dale FyeOwner, Developing Solutions LLCCommented:
What version of Access are you using?  Are you using Office 365?

I'm not familiar with O365, but a normal connection string for a pass-through query would look something like:

ODBC;DRIVER=DriverName;SERVER=ServerName;Trusted_Connection=Yes;APP=SSMA;DATABASE=DatabaseName

Where Drivername might be on of:
SQL Server Native Client 12.0
SQL Server Native Client 11.0
SQL Server Native Client 10.0
SQL Server

ServerName could either be the name of the Server (in your case, they may be the same) or an IP address

Database name would refer to the name of the database that the query applies to.  In my case, I use:
AppName_Prod
AppName_Dev

the VBA to change the connection string would look like:
strConn = "ODBC;DRIVER=DriverName;SERVER=ServerName;Trusted_Connection=Yes;APP=SSMA;DATABASE=DatabaseName"
currentdb.Querydefs("PassThruQueryName").Connect = strConn

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
deer777Author Commented:
I am using Access 2010
0
PatHartmanCommented:
The version of Access doesn't affect the connection string.  It is the version of the driver and the server that you need to be concerned with.  Here is a relinker I made that lets you swap between various production and staging libraries.  I used part of the server instance name to define what needed to be swapped.  At the end, all the pass-through queries are relinked.
RelinkODBC.accdb
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.