Macro to change a query

  • Thread starter Thread starter William McNeill
  • Start date Start date
W

William McNeill

I have a little over 20 queries that I need to make a very simple
modification on. Basically, all of the times where the field name "OWg"
appears in the SQL of the query, if I could replace that with "OSg" my work
would be done. I have been looking in the Macros to see if I could find a
way to design a Macro in which I could select a query, run the Macro, and it
open the query in SQL and make those changes. I can not seem to come up with
the Macro needed to begin with. Is this possible to do with a Macro?
 
William,

It would be quite difficult with a macro. But you could certainly do this
with a VBA procedure. However, even then, if it was mine I would just go
into the design of the 20 queries one by one and change them manually. You
could probably do that in about the same amount of time as it took you and I
to write these posts to the newsgroup.

Anyway, for the record, here is the skeleton of the code you could use...

Dim qdf As DAO.Querydef
For Each qdf In CurrendDb.QueryDefs
qdf.SQL = Replace(qdf.SQL, "OWg", "OSg")
Next qdf

You would have to make sure that this only affects to queries you want it to
affect. And you would have to make sure the queries do not inadvertently
include a "owg" string somewhere else, within another word.
 
Thanks Steve, I will give this a try. If it gets too complicated, I will
probably do what you said and do each one manually. Thanks again and have a
great day!!
 
Back
Top