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
Who is Participating?
Dale FyeCommented:
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:


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:

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

deer777Author Commented:
I am using Access 2010
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.