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.
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
To resolve this issue, update the VBA code to use the new UserInfoGet object. The RetrieveGlobals9 userinfo object is no longer required.
- Comment out the following line:
'Dim userinfo As New retrieveuserinfo
- 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.Connection
Set cn = UserInfoGet.CreateADOConnection
- 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_id
cn.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 Declarations
Option Explicit
Dim cn as New ADODB.Connection
Dim cmd as New ADODB.Command
Dim rst as New ADODB.RecordSet
'Setup the connect and command objects in the Window_BeforeOpen event
Private 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 code
Set cn = UserInfoGet.CreateADOConnection
cn.DefaultDatabase = UserInfoGet.IntercompanyID
'Setup the command objects active connection
cmd.ActiveConnection = cn
'Specify the ADO command type
cmd.CommandType = adCmdText
End Sub
Private Sub ItemNumber_Changed()
If ItemNumber <> "" Then
cmd.CommandText = "select * from IV00101 where (ITEMNMBR = '" _
& ItemNumber & "')"
Set rst = cmd.Execute
StandardCost = rst!STNDCOST
End If
End Sub
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 Declarations
Option Explicit
Dim cn as New ADODB.Connection
Dim cmd as New ADODB.Command
Dim rst as New ADODB.RecordSet
'Setup the connect and command objects in the Window_BeforeOpen event
Private Sub Window_BeforeOpen(OpenVisible As Boolean)
Dim userinfo As New retrieveuserinfo
Set cn = userinfo.Connection
cn.DefaultDatabase = userinfo.intercompany_id
'Setup the command objects active connection
cmd.ActiveConnection = cn
'Specify the ADO command type
cmd.CommandType = adCmdText
End Sub
Private Sub ItemNumber_Changed()
If ItemNumber <> "" Then
cmd.CommandText = "select * from IV00101 where (ITEMNMBR = '" _
& ItemNumber & "')"
Set rst = cmd.Execute
StandardCost = rst!STNDCOST
End If
End Sub
Article ID: 972245 - Last Review: July 13, 2012 - Revision: 5.0
Applies to
- Microsoft Dynamics GP 10.0
- Microsoft Dynamics GP 2010
- Modifier with Visual Basic for Applications
| kbexpertiseadvanced kberrmsg kbsurveynew kbexpertisebeginner kbtshoot kbmbsmigrate kbprb kbexpertiseinter KB972245 |