Solved

Replace table in Access query

Posted on 2011-09-03
4
215 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 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

688 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