How to Convert Access Macro to VB code

Converting Access Macro to VBA code Easy

The Embedded Macro is a popular method that used in the sample Access file version 2007, 2010 and 2013 from Microsoft. The Embedded Macro is used to collect a group of commands that require only few of input for each command from the developer. It also can be copied easily from one location to another. When a button is copied to a new location the Macro command of that button will stay with a new button, not like an Event Procedure.

The sample Access database files from Microsoft website have many useful commands or functions under the Embedded Macro. If you are using the Event Procedure for your VBA in your program and you want to know how the VBA code look like from the Embedded Macro you can convert the Macro commands to Visual Basic (VB). The step below will show you how to convert Macro to VB.

Step #1 Open your form under the design view and click on the button or text box that has a function/command behind the button/textbox.

embedded macro

 

 

 

 

 

 

 

 

If you want to see the Macro function, you can click on three dots (…) behind the [Embedded Macro] to open the set of command inside the Embedded Macro as shown below. Under this dropdown combo box, you will see 4 sets of commends under the Embedded Macro:
1. Set a select user from the list as a temp CurrentUserID
2. On Error then go to Next command
3. Run Requery command for the data source of this combo box.
4. Run Refresh command to update the related data on the current form.
open macro

 

 

 

 

 

 

Step #2 Under the form design view, click on the “Convert Form’s Macro to Visual Basic” to convert Macro to VB. A small pop up window will display and click on Convert and click Finish button.

convert

 

 

 

 

 

 

Step #3 After click on the Convert button and finished the convert process, all Macro commands under this form will be converted to VB code. You will see the change on the After Update from Embedded Macro to Event Procedure. Now open the Event Procedure, you will see the VBA code converted from Macro.

convert done

 

 

 

 

 

 

 

For example below, the Macro is converted to VBA for a combo box “cboCurrentEmployee” on its After Update property. The function under this combo is assigning a new selected employee to a temp current employee for this database that can be used anywhere while this program is still opened. It also runs a command of Requery of data source of this combo box and refreshes data as you can see below.

vba code