Avatar of kwarden13
kwarden13

asked on 

Replace Table Name used in QUERIES

I changed a table name and need to replace the name in 100+ queries. Any easy way to do this?
Microsoft AccessVisual Basic ClassicSQL

Avatar of undefined
Last Comment
Nick67
Avatar of Patrick Matthews
Patrick Matthews
Flag of United States of America image

Get this indispensable tool for Access developers:

http://www.rickworld.com/products.html

Not free, but TOTALLY worth the price.
ASKER CERTIFIED SOLUTION
Avatar of DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
DatabaseMX (Joe Anderson - Former Microsoft Access MVP)
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
10 seconds apart :)
Avatar of kwarden13
kwarden13

ASKER

I cant. it wont let me download it onto my work computer. I dont have admin rights.
You could try looping through your QueryDefs collection, then, but that is a potentially dangerous route...
Avatar of jerryb30
jerryb30
Flag of United States of America image

Probably more dangerous to try to hand-edit 100+ queries.  Why is the table name so important?  

Here's why.  Suppose you had a table name Customer, which had a column named CustomerID.

Now, you want to update all your queries to refer to tblCustomers instead of Customer.  If you do a straight replace of "tblCustomers" for "Customer", then "Customer.CustomerID" can turn into "tblCustomers.tblCustomersID".

:)
Avatar of jerryb30
jerryb30
Flag of United States of America image

Easiest solution is to create a query with the same name as the old table, whose data source is the newly named table.
"You could try looping through your QueryDefs collection, "
And only some of they queries need to be renamed probably.

mx
Avatar of kwarden13
kwarden13

ASKER

Any code for looping through? I am not sure where to put the code?!?
even with a code solution, Patrick has an excellent point @ http:#a36184018 ... so, the code has to take into account the 'exact match' type of find, etc.  This or course ... is all handled in F&R noted above.  If there is anyway you can figure out how to use that, I would seriously try and find (no pun) a way.  Sooooooo much has already been handled for you ... years of development and perfection.

mx
Avatar of jerryb30
jerryb30
Flag of United States of America image

What does not work about my suggestion?
Avatar of kwarden13
kwarden13

ASKER

I built the database. i can go through every query but i rather not.
Jerry,

Never thought to try that.  If it works, it's pure genius.  Of course, if it works, it also makes me very worried about Access :)

(IMHO, in a perfect world, Access would enforce distinct names among database objects...)

Patrick
Avatar of jerryb30
jerryb30
Flag of United States of America image

Externally, an Access table and query look the same. Which is why they cannot share a name.  It is no different from having a linked table versus one resident in the database.
"Access would enforce distinct names among database objects...)"
Yeah ... and even Northwind doesn't do that, lol.

mx
Avatar of Nick67
Nick67
Flag of Canada image

In Access 2010, with the settings I have in place, it just does it on the fly by itself.
In a test shim, if I rename Table1 to Table2, in the queries the table name changes auto-magically.

You have to have Perform Name Auto-Correct turned on--and turning it on, doing the change and turning it off again shouldn't be a big deal.
Access 2003 does it to if auto-correct is on, too.

For performance reasons, I usually have it turned off in production--but it's convenient in situations like this
Microsoft Access
Microsoft Access

Microsoft Access is a rapid application development (RAD) relational database tool. Access can be used for both desktop and web-based applications, and uses VBA (Visual Basic for Applications) as its coding language.

226K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo