22 June, 2009

Removing a Reference to a Field or Object in VBA

While upgrading some customizations to GP 10 I encountered a situation in which I needed to remove references to 4 fields out of 60+ on Sales Transaction Entry that had been added to VBA. Many of the valid references were to invisible fields. For a couple of reasons the standard method of copying the code to .txt, noting all of the fields that needed to be added back, removing the window from VBA, adding the window back along with all of the valid fields, and then pasting the code back in seemed very laborious.

It made sense in this instance to spend a few minutes trying to remove the invalid references without having to click so many buttons.

The steps to remove a field reference from a VBA Project are:

1. Export your Form with VBA to a .package file (Tools>>Customize>>Customization Maintenance).
2. Open the .package file with notepad and find the references to the field you need to remove.
3. Remove any references to your field. Most importantly, remove the WindowField reference. This is how VBA knows about the field. It will look like this:

WindowField "Transfer Button"
{
ArrayIndex "0"
DisplayName "Transfer"
Local "false"
ProgrammerName "Transfer Button"
}


4. Save your .package file and import the modified version. (Tools>>Customize>>Customization Maintenance).

NOTE: The technique described here directly modifies the contents of a customization package with Notepad. This technique is not supported by Microsoft Dynamics GP support.