Developing for Dynamics GP

by David Musgrave (Perth, WA, Australia) and the Microsoft Dynamics GP Developer Support Team (Fargo, ND, USA)

Customising the Company Login window series Part 2 - Visual Basic for Applications

Customising the Company Login window series Part 2 - Visual Basic for Applications

Rate This
  • Comments 3

David Meego - Click for blog homepageFollowing 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:

  1. Load Microsoft Dynamics GP and get the Company Login window showing (either on first login or by switching companies after login). 
     
  2. 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.
     
  3. 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.
     
  4. 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.
     
  5. Best practice is to require variable declaration, so select Tools >> Options and make sure the Require Variable Declaration option is checked and click OK.
     
  6. 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.
     
  7. 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.
     
  8. 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.
     
  9. Finally, select from the Visual Basic Editor's menus select Debug >> Compile Microsoft Dynamics GP and File >> Save Microsoft_Dynamics_GP.
     
  10. 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:  

Company Login Code

Option Explicit

Private Sub Window_BeforeOpen(OpenVisible As Boolean)
    Dim Adjust As Integer
    Adjust = 230
   
    Company.Left = Company.Left - Adjust
    Company.Width = Company.Width + Adjust
    Rememberthiscompany.Left = Rememberthiscompany.Left - Adjust
    Rememberthiscompany.Width = Rememberthiscompany.Width + Adjust
    Server.Left = Server.Left - Adjust
    Server.Width = Server.Width + Adjust
    UserID.Left = UserID.Left - Adjust
    UserID.Width = UserID.Width + Adjust
    CurrentUsers.Left = CurrentUsers.Left - Adjust
    'CurrentUsers.Width = CurrentUsers.Width + Adjust
    UsersAllowed.Left = UsersAllowed.Left - Adjust
    'UsersAllowed.Width = UsersAllowed.Width + Adjust
End Sub

 

 

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. 

David

Attachment: Switch Company.zip
  • Post from Mark Polino at DynamicAccounting.net

    mpolino.com/.../customising-company-login-window-series-part-2-visual-basic-applications-developing-dynamics-gp

  • Hi David,

    This customization comes in just handy.. since our company has been acquired, I have to look into renaming all our GP companies and they will all start with the same lengthy prefix 'Ultra Electronics', which adds another 20-something characters and thus render the list unreadable from the pull-down menu..

    I've tried to import your package into my test bed system to see if it works, and even after following your directions and setting the Options for the variable declarations, every time I switch company I get an error about permission denied. When clicking on the Debug button, it stops on the line 'UsersAllowed.Left = UsersAllowed.Left - Adjust

    any ideas where to fix this ? I thought that there is no need to select the GP security for alternate forms ?

    Thank you,

    Beat

  • Hi Beat

    Comment out that line and see if it works.

    What version are you using?  This was coded against GP 2013 SP2.

    David

Page 1 of 1 (3 items)
Comments Information

PLEASE READ BEFORE POSTING

Please only post comments relating to the topic of this page.

If you wish to ask a technical question, please use the links in the links section (scroll down, on right hand side) to ask on the Newsgroups or Forums. If you ask on the Newsgroups or Forums, others in the community can respond and the answers are available for everyone in the future.

Leave a Comment
  • Please add 7 and 7 and type the answer here:
  • Post