Changes to the Command Buttons and the Button Wizard

If you open a form in design mode and try to create a button using the button wizard you will notice something different. Actually, you might not even notice it at first. The UI is pretty much the same as usual, except for a couple of arcane type of commands that aren’t available anymore.

So, what’s new?

The code behind the command buttons. Instead of having VBA functions, they have embedded macros. And very simple ones, by the way.

Why did we change them?

Well, for starters the VBA code that was generated was, uh, yucky. For example, if you create a “Record Operations > Print Record” button, this is the VBA it generates:

Option Compare Database

Private Sub Command6_Click()

On Error GoTo Err_Command6_Click

    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70

    DoCmd.PrintOut acSelection

Exit_Command6_Click:

    Exit Sub

Err_Command6_Click:

    MsgBox Err.Description

    Resume Exit_Command6_Click

   

End Sub

How do you like the DoMenuItem action? Easy to change, huh?

So here’s what the equivalent embedded macro looks like:

            RunCommand (SelectRecord)

            RunCommand (PrintSelection)

Which one do you think is easier to understand and change? You betcha the embedded macro is. Also, this button will work even when code is disabled in the database, which is a nice side benefit.