MS Access SQL Server Table Connection

I need to connect to a SQL Server table from MS Access.  The table name in Access is 123 but the SQL Server table name is 123_v_username.  I need the table name (123) to stay the same in Access but only change the connection string from SQL Server to change to 123_v_username.  How would I write the code to do this.
Who is Participating?
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.

Pawan KumarDatabase ExpertCommented:
You can do like below

Pass the name of the table at runtime

Exec('' select columnname from ' + variabletablename + '')
Jim Dettman (EE MVE)President / OwnerCommented:
You'd want to modify the tabledef's connect property.

 In the VBA editor, call up the debug window (Ctrl/G).  Type:

? CurrentDB().tabledefs("123").Connect

and hit return.   You'll see the server, database, table name, etc.   Since this is a string, you can use Instr() to locate what you want to change, Left$(), Mid$(), etc to pick out the parts, build a new string, and update the connect property with that.


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
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

From novice to tech pro — start learning today.