Error message when you run VBA code that uses RetrieveGlobals9.dll after you upgrade to Microsoft Dynamics GP 10.0 or Microsoft Dynamics GP 2010: "Operation is not allowed when the object is closed"

This article has been archived. It is offered "as is" and will no longer be updated.
Symptoms
You upgrade to Microsoft Dynamics GP 10.0 or Microsoft Dynamics GP 2010. When you run Microsoft Visual Basic for Applications (VBA) code that uses RetrieveGlobals9.dll, you receive the following error message: 
Run-time error ‘3704’:
Operation is not allowed when the object is closed.
Cause
This issue occurs because RetrieveGlobals9.dll cannot be used in Microsoft Dynamics GP 10.0 or Microsoft Dynamics GP 2010. RetrieveGlobals9.dll cannot create an ADO connection when a customization that was written in Microsoft Dynamics GP 9.0 is imported into Microsoft Dynamics GP 10.0 or Microsoft Dynamics GP 2010. When the default database assignment is tried by the following statement, you receive the error message that is described above: 
cn.DefaultDatabase = userinfo.intercompany_id
Resolution
To resolve this issue, update the VBA code to use the new UserInfoGet object. The RetrieveGlobals9 userinfo object is no longer required.
  1. Comment out the following line:
    'Dim userinfo As New retrieveuserinfo
  2. Comment out the line that uses the userinfo object connection method to return an ADO connection object. Add a new line that uses the built-in UserInfoGet object instead:
    'Set cn = userinfo.ConnectionSet cn = UserInfoGet.CreateADOConnection
  3. Comment out the line that uses the userinfo object intercompany_id method to set the DefaultDatabase property of the connection object. Add a new line that uses the built-in UserInfoGet object instead:
    'cn.DefaultDatabase = userinfo.intercompany_idcn.DefaultDatabase = UserInfoGet.IntercompanyID
Make sure that no changes are made to the remaining code. Only the lines of code that create and set up the ADODB.Connection object have to be changed.

When you finish these steps, the code should resemble the following VBA code sample:
'Declare variables in the General DeclarationsOption ExplicitDim cn as New ADODB.ConnectionDim cmd as New ADODB.CommandDim rst as New ADODB.RecordSet'Setup the connect and command objects in the Window_BeforeOpen eventPrivate Sub Window_BeforeOpen(OpenVisible As Boolean)'Dim userinfo As New retrieveuserinfo'Old RetrieveGlobals9 code'Set cn = userinfo.Connection'cn.DefaultDatabase = userinfo.intercompany_id'New Dynamics GP 10.0 or Microsoft Dynamics GP 2010 codeSet cn = UserInfoGet.CreateADOConnectioncn.DefaultDatabase = UserInfoGet.IntercompanyID'Setup the command objects active connectioncmd.ActiveConnection = cn'Specify the ADO command typecmd.CommandType = adCmdTextEnd SubPrivate Sub ItemNumber_Changed()	If ItemNumber <> "" Thencmd.CommandText = "select * from IV00101 where (ITEMNMBR = '" _  & ItemNumber & "')"Set rst = cmd.ExecuteStandardCost = rst!STNDCOSTEnd IfEnd Sub
More information

Microsoft Dynamics GP 9.0 VBA code

The following VBA code sample uses the RetrieveGlobals9.dll to retrieve the standard cost for an inventory item and assign the value that was retrieved to a custom field named "StandardCost." You can apply this code to the Item Transaction Inquiry window.

Note For this code to be run, the VBA project must have a reference added to Microsoft ActiveX Data Objects 2.8 Library and to RetrieveGlobals9.dll.
'Declare variables in the General DeclarationsOption ExplicitDim cn as New ADODB.ConnectionDim cmd as New ADODB.CommandDim rst as New ADODB.RecordSet'Setup the connect and command objects in the Window_BeforeOpen eventPrivate Sub Window_BeforeOpen(OpenVisible As Boolean)Dim userinfo As New retrieveuserinfoSet cn = userinfo.Connectioncn.DefaultDatabase = userinfo.intercompany_id'Setup the command objects active connectioncmd.ActiveConnection = cn'Specify the ADO command typecmd.CommandType = adCmdTextEnd SubPrivate Sub ItemNumber_Changed()	If ItemNumber <> "" Thencmd.CommandText = "select * from IV00101 where (ITEMNMBR = '" _  & ItemNumber & "')"Set rst = cmd.ExecuteStandardCost = rst!STNDCOSTEnd IfEnd Sub
great plains, visual basic, VBA
Properties

Article ID: 972245 - Last Review: 01/15/2015 16:46:47 - Revision: 6.0

Microsoft Dynamics GP 10.0, Microsoft Dynamics GP 2010, Modifier with Visual Basic for Applications

  • kbnosurvey kbarchive kbexpertiseadvanced kberrmsg kbsurveynew kbexpertisebeginner kbtshoot kbmbsmigrate kbprb kbexpertiseinter KB972245
Feedback