This question came up in a recent Dynamics GP newgroup post. A developer was trying to run some Visual Basic for Applications (VBA) code in response to the company selected by the user from the Company drop-down list, but was unsuccessful determining which company was selected by the user.
From a customization and development perspective, the Company drop-down list presents the following challenges:
1) Different users may have access to different companies, therefore, the number of companies displayed by the drop-down may vary.
2) The company drop-down list does not store the company ID. It stores a positional value for the company record being displayed.
3) Companies are displayed in the drop-down by Company ID. However, due to challenge number 1, company IDs may present gaps in the sequence based on user access.
The following VBA code shows how to retrieve the company selected by the user based on the user access to the different company databases. The code executes a SQL statement against the system database when the DDL focus is lost. Since the user is already logged in into the system, it is possible to create an ADO connection with the CreateADOConnection() method.
Until next post!
Mariano Gomez, MVP
Maximum Global Business, LLC