?
Solved

Replace table in Access query

Posted on 2011-09-03
4
Medium Priority
?
220 Views
Last Modified: 2012-05-12
I have a complicated query in Access and I was to replace all tables in it with the same table structure but the name are different.

How can I do this without editing the query and do it in design view?
0
Comment
Question by:Gerhardpet
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 75

Accepted Solution

by:
DatabaseMX (Joe Anderson - Microsoft MVP, Access and Data Platform) earned 2000 total points
ID: 36478671
Easy:

Find & Replace - best ever tool.  Get it!

http://www.rickworld.com/products.html#Find%20and%20Replace%209.0

mx
0
 
LVL 10

Expert Comment

by:plummet
ID: 36480090
When I need to do this I go to SQL view, copy the query, paste it into a text editor (or Notepad!) and replace the old name with the new one. Then I copy the text back into the SQL view in Access. Simple.

Alternatively, add the new table into design view, and for each column change the "Table:" row to the new table. When that's complete remove the old table from the designer.

I hope that helps.
0
 
LVL 30

Expert Comment

by:hnasr
ID: 36482240
One way:
Query: change_table_name_q
Select b.f1 From b;

A lookup table: change_table_name (table_name, changeTo)
table_name      changeTo
b                         a

Click event code:
Private Sub cmdChangeTableName_Click()
    Dim rs As Recordset
    Dim qsql As String
    qsql = CurrentDb.QueryDefs("change_table_name_q").sql
    Set rs = CurrentDb.OpenRecordset("change_table_name")
    Do While Not rs.EOF
        qsql = Replace(qsql, vbCrLf, " ", 1, True) ' replace cr and lf
        qsql = Replace(qsql, ";", " ", 1, True) 'replace ; to space
        qsql = Replace(qsql, " " & rs(0) & ".", " " & rs(1) & ".", 1, True) 'replace table.
        qsql = Replace(qsql, " " & rs(0) & " ", " " & rs(1) & " ", 1, True) 'replace table
        rs.MoveNext
    Loop
    CurrentDb.QueryDefs("change_table_name_q").sql = qsql
End Sub
changeTableName.mdb
0
 
LVL 1

Author Comment

by:Gerhardpet
ID: 36510244
Find & Replace is a great tool indeed!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question