Following on from my previous post: Customising the Company Login window series Part 1 - Introduction, here is the method to create a solution using Visual Basic for Applications (VBA).
As discussed in the earlier post, the problem we are trying to overcome is that the company drop down list on the Company Login window is not wide enough to show a long company name. This can make it difficult to select the correct company when the company names are long and differ only by some characters at the end of the name.
Below is a screenshot of the original window from Microsoft Dynamics GP 2013.
Following are the step by step instructions on how to use Visual Basic for Applications (VBA) code to "modify" the window:
- Load Microsoft Dynamics GP and get the Company Login window showing (either on first login or by switching companies after login).
- Now that the window is open we need to add it to Visual Basic, but as the window is modal we cannot use the menus. So press the keyboard shortcut Ctrl-F11 to add the window.
- Then we need add the fields to Visual Basic. Press the keyboard shortcut Shift-F11 to enter selection mode (note the cursor changes). Now click on each of the fields on the right hand side (including the checkbox). Once all fields have been added, press Shift-F11 to exit selection mode.
- Now that the resources have been added to Visual Basic, we can start writing the code needed. Press Alt-F11 to open the Visual Basic Editor.
- Best practice is to require variable declaration, so select Tools >> Options and make sure the Require Variable Declaration option is checked and click OK.
- On the top left of the Visual Basic Editor is the Project Explorer window which will have a list of application dictionaries installed in Microsoft Dynamics GP (if the window is not showing press Ctrl-R). Locate the Microsoft_Dynamics_GP project and expand the tree to show the Microsoft Dynamics GP Objects and double click on the CompanyLogin (Window) to open the script editor.
- From the resources drop down list (directly above the script editor on the left hand side), select Window. From the event drop down list (on the right hand side), select BeforeOpen (if not already selected). This will generate the declaration for the Window_BeforeOpen() event.
- Now we can add the code to move the left hand edge of the fields to the left and increase the field widths to fill the space created (except for the numeric fields). Using a variable makes it easier to tweak the changes to meet your requirements. The maximum adjustment that fits nicely in the window is 230 pixels. The code for this customisation is shown below.
- Finally, select from the Visual Basic Editor's menus select Debug >> Compile Microsoft Dynamics GP and File >> Save Microsoft_Dynamics_GP.
- Now you can re-open the Company Login window to see your changes. If you want to tweak the adjustment, change the value, recompile, save and test again. Close the Editor when you are finished.
Here is a screen shot of the window with the full 230 pixel adjustment:
Below is the code used:
The VBA package for this customisation is attached to the bottom of this article. You can use Tools >> Customize >> Customization Maintenance to load the package.
Thanks to Patrick Roth and Aaron Berquist for their feedback on this customisation.
Hope you find this useful and educational.