Replace SQL in Query

AgDawg

Registered User.
Local time
Yesterday, 21:26
Joined
Oct 12, 2012
Messages
24
I am setting a location database for many locations. These are all connected to sharepoint. What I need to do and am doing manually to this point is replacing table names in all my querys. Is there any code that I can change just the sql in all the querys? An example is that my template database has a table named tblprofile_Demo and I need to change to tblprofile_Memphis. This would be done after I have imported the location sharepoint lists into the template.
 
Are your SQL Queries you speak of saved as QueryDef objects in the Access DB? If so, then yes just create an DAO.QueryDef object and update to your heart's content.
 
A example of using querydef :

Code:
    Dim db As DAO.Database
    Dim qd As DAO.QueryDef
    Dim strSQL As String

    Set db = CurrentDb

    Set qd = db.QueryDefs("QueryNAME")
    qd.SQL = Replace(qd.SQL, "FROM tblprofile_Demo;", "FROM tblprofile_Memphis;")
Here is a find and replace program for all objects (tables, queries, reports, etc)
http://www.rickworld.com/

A free version that does find and replace on queries is
http://www.skrol29.com/us/vtools.php
 

Users who are viewing this thread

Back
Top Bottom