The specific issue was that VBA cannot get the name of the company from the DDL (drop down list), it can only give you the position. Also the position in the list doesn’t have any bearing on the company id of the company displayed. It is just an ordered list by alphanumeric sorting by the Company Name field.
The question wasn’t specific to when exactly the user needed to see this message. When initially I read the question and based on how it was posed, it seems they wanted to know right when the DDL was selected. But it could have been when the OK button was pressed and it also could be just after they log in.
Given that the technique used would be different, I will present both solutions.
For this solution, we will assume that the programmer needs to know the company after the user logs into Dynamics GP in order to give them some information or take a specific action.
The easiest way to do this it to use a Window_AfterClose() event on the Company Login window (Switch_Company form in Dexterity) and use the UserInfoGet object to retrieve the company logged in.
In the VBA code sample below, before the window opens we see what the current company is. We could either being logging into Dynamics GP for the first time or just switching companies. And if switching companies, we might press Cancel or just re-select the same company. So by checking the previous logged in company and comparing we only show our message if the company we are going to really changed.
While the solution given for the first situation is OK if we want to let the user log in, it is possible that we might want to give a message before the GP login occurs. Or potentially stop the user from being able to log into the company for some specific reason.
If that is the case, we would then need to know the selected company before the Company Login window was closed. The only way to do that is to know the company name selected in the Company DDL.
Because we cannot directly read the name from the Company DDL field, we have to pull the information directly from SQL in the order that Dynamics is displaying it. Then we’d know the company being selected and could act upon that.
// Copyright © Microsoft Corporation. All Rights Reserved.
// This code released under the terms of the
// Microsoft Public License (MS-PL, http://opensource.org/licenses/ms-pl.html.)