Microsoft Access VBA Macro Programming

(Tina Sui) #1
The code sets up strings to hold the name of the query and the search and replace
information. These are then loaded with the relevant strings. The variable Temp is loaded
with the SQL statement for the target query.
A For..Next loop is used to iterate through the SQL statement. TheInstrfunction is
usually employed to check whether the search string has been found, but in this case a
movable start position is used, defined by n from the For..Next loop.
If the search string has been found, the replacement string is inserted at the correct point
into the variable Temp. The value n is then incremented by the For..Next loop and another
iteration is performed.
This ensures that every instance of the search string will be changed to the replace string,
no matter how many are in the SQL statement.
This provides a far quicker and better way of making changes to queries than trying to do
it manually. It is very easy to make a mistake on a manual basis, particularly if the query is
long and complicated.

300 Microsoft Access 2010 VBA Macro Programming

Free download pdf