Using the New UserInfo Object in VBA for Microsoft Dynamics GP 10.0

With the release of MS Dynamics GP 10.0, the RetrieveGlobals.dll and RetrieveGlobals9.dll libraries available for releases 8.0 and 9.0 respectively, are no longer available to VBA customization developers.

Instead, VBA has been boosted with a new UserInfo object that will allow developers direct access to login information for the current user signed in into the application, providing a more transparent and integrated approach than the traditional RetrieveGlobals external objects.

The following code snippet shows how to make use of the UserInfo object and pass its information to an ADODB.Connection object.

Window_BeforeOpen() Event

Private Sub Window_BeforeOpen(ByVal OpenVisible As Boolean)
cn = UserInfoGet.CreateADOConnection
cn.DefaultDatabase = UserInfoGet.IntercompanyID
cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
End Sub

In the above example, the Window_BeforeOpen event will initialize the connection information.

SomeField_Changed() Event

Option Explicit On
Dim UserInfoObj As UserInfo
Dim CompanyName As String

Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim sqlstring As String

Private Sub SomeField_Changed()
If SomeField = \"\" Then
Exit Sub
cmd.CommandText = \"SELECT * FROM dbo.YourTable WHERE(SomeColumn ='\" &_
SomeField & \"')\"
rst = cmd.Execute

' -- Do something with the result set
End If
End Sub

The Changed() event script will then consume the connection created in Window_BeforeOpen() and run a query against a database. The result is stored in a recordset.

Enjoy the new UserInfo object in VBA and make go make those changes to your customizations.

Until next post!

Mariano Gomez, MIS, MCP, PMP
Maximum Global Business, LLC


Popular posts from this blog

Power Apps - Application Monitoring with Azure Application Insights

eConnect Integration Service for Microsoft Dynamics GP 2010

Troubleshooting the Microsoft Dynamics GP 2013 Web Client - Part 3