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
Solved

Replace table in Access query

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Read about achieving the basic levels of HRIS security in the workplace.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

839 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