Total Visual CodeTools Macro Recorder
The Macro Recorder is a very powerful tool that lets you record a complex
series of keystrokes and replay them. It's ideal for situations where the
same set of tasks need to be repeated.
Note that the Macro Recorder only records keystrokes and not
references to the menu or mouse movements and clicks.
To start, select macro recorder from the Total Visual
CodeTools menu or toolbar:

The Macro Recorder Toolbar appears:

These buttons are available:
 |
Start Recording
Press this then enter your keystrokes. |
 |
Stop Recording
This is enabled after you press the start button. When
you're done with your series of keystrokes, press this
button. |
 |
Play
This is enabled after you press the Stop Recoding
button. Move your cursor to the location where you want
to repeat your keystrokes, then press Play. Your
keystrokes are repeated exactly the way you originally
entered them. |
FYI, the appearance of the buttons may differ based on your
Windows and VB6/VBA version but the order is always the same.
Example
Here's a simple example of how you may can use the macro
recorder. Let's say we want to copy fields from one table to
another. This is the code we want to write:
-
Dim dbs As DAO.Database
Dim rstSource As DAO.Recordset
Dim rstTarget As DAO.Recordset
Set dbs = CurrentDb
Set rstSource = dbs.OpenRecordset("tblSource")
Set rstTarget = dbs.OpenRecordset("tblTarget")
Do While Not rstSource.EOF
rstTarget![FirstFieldName] = rstSource![FirstFieldName]
rstTarget![SecondFieldName] = rstSource![SecondFieldName]
rstTarget![ThirdFieldName] = rstSource![ThirdFieldName]
rstTarget![LastFieldName] = rstSource![LastFieldName]
rstSource.MoveNext
Loop
But before we wrote that code, we only had the list of fields
inside the Do..Loop:
- Do While Not rstSource.EOF
FirstFieldName
SecondFieldName
ThirdFieldName
NextFieldName
LastFieldName
rstSource.MoveNext
Loop
Rather than manually entering the text for each line,
wouldn't it be easier to do it just once for the first line and
repeat it for the others?
Recording Keystrokes
It's simple! Move the cursor to the beginning of
FirstFieldName, then record the keystrokes necessary to convert
that line to this:
-
rstTarget![FirstFieldName] =
rstSource![FirstFieldName]
Start by pressing the
Start Recording button. Enter the keystrokes to create the first
line from the field name, then move to the same place on the
next line:
| Keystrokes |
Action and Line Appearance |
| |
FirstFieldName |
| Shift End |
Highlight text to copy:
FirstFieldName |
| Ctrl C |
Copy field name to the clipboard |
| Left |
Go to the beginning of the highlighted
text |
| rstTarget![ |
Enter the first part of the line:
rstTarget![FirstFieldName |
| End |
Go to the end of the line |
| ] = rstSource![ |
Enter the second part:
rstTarget![FirstFieldName] = rstSource![ |
| Ctrl V |
Paste the field name:
rstTarget![FirstFieldName] = rstSource![FirstFieldName |
| ] |
Finish the line:
rstTarget![FirstFieldName] = rstSource![FirstFieldName] |
| Home Down |
Move to the beginning of the next line |
Press the
Stop Recording button to save our keystrokes.
Playing Back the Keystrokes
Pressing the
Play button replays our keystrokes, and presto, the next line of
code is written:
-
rstTarget![SecondFieldName] =
rstSource![SecondFieldName]
Press Play for the next line, and next line, etc., and you
quickly get the desired result:
- rstTarget![FirstFieldName] =
rstSource![FirstFieldName]
rstTarget![SecondFieldName] = rstSource![SecondFieldName]
rstTarget![ThirdFieldName] = rstSource![ThirdFieldName]
rstTarget![NextFieldName] = rstSource![NextFieldName]
rstTarget![LastFieldName] = rstSource![LastFieldName]
This example is fairly simple. For more complex repetitive
steps, the Macro Recorder will ensure accuracy and save you tons
of time!