Refactoring code is something I do often. Trying to find ways to make things simpler and more readable are two reasons of many that I do this. As I work on code and refactor it, I find myself continually, daily, using tools to find and replace code, and not quite as often, but still a lot, I look to find and/or replace keywords inside of the properties of Access objects.
My first tool I began using for Find and Replace was simply the VBE editor. Hitting CTRL-F or CTRL-H you can quickly bring up the system dialog to find and replace code in modules. And it’s not too bad. You can’t do a mass Find and Replace for all instances with 1 button, but you can quickly cycle through all instances, which are brought up in context with the code.
The shortcomings of the built-in system tool is that it only examines the VB Code.
Initially ,when I needed to search for terms inside of object properties like forms and form controls (say I have a function call inside of a button OnClick property for example), since I was using OASIS for version control, I was able to search the exported text files of the objects for the term. This was helpful and also searched through code, but suffered from a number of setbacks. Two problems were that the source code words could sometimes be split up with a newline character right inside the string I’m searching for so it was not found, and the second problem being that it was a bit of work reviewing exactly where I could find the item and getting there. Nothing would just take me there automatically.
Enter 2 FInd and Replace tools that I use quite often:
- MZ-Tools – Productivity Tools for Visual Studio .NET (C#, VB.NET), Visual Basic and VBA (mztools.com)
- Find and Replace for MS-Access – Access Dev Tools
MZ-Tools has a Find and Replace tool that shows all results in one window and allows you to move between them and jump right to the code if you want and to quickly redo the search. It also lets you define the scope and use a few options to define search terms using wilcards and regular expressions among other things. It’s quite powerful. This is what I tend to use the most, although it does not search objects.
Enter number 2 Find and Replace for MS-Access from Access Dev Tools. This tool is really fantastic. It will find and display in context Objects and their Properties where it finds the given search term. It also can use regular expressions and powerful search term options. I use it if I need to search everything. I don’t typically use this as my global find and replace tool though because it’s a little slower than MZ-Tools and it does not allow me to jump right to the text that was found, although it nicely handles replacing if that’s what I’m doing.
So, I highly recommend these useful tools. MZ-Tools does a lot more as well, but the feature I use most often is the find and replace.
For refactoring in particular, I am interested in learning more about the RubberDuckVBA tool I’m using for testing. It has a refactor menu, but I haven’t quite learned how to use it yet.
In any case, I know there are a lot more find and replace tools out there as well as other productivity increasing tools. Feel free to share with me the tools you use the most.