Wednesday, October 8, 2014

Dynamics GP - Modifier and VBA Visual Basic - ODBC Connection

Private Sub GetItemCost()

Dim objRec
Dim objConn
Dim cmdString

Set objRec = CreateObject("ADODB.Recordset")
Set objConn = CreateObject("ADODB.Connection")

objConn.ConnectionString = "Provider=SQLOLEDB;Data Source=GP\GPSQL;Initial Catalog=TWO;User Id=sa;Password=pw"
objConn.Open


cmdString = "Select CURRCOST from IV00101 where (ITEMNMBR='" + ItemNumber + "')"

Set objRec = objConn.Execute(cmdString)

If objRec.EOF = True Then
ManufacturingOrderReceiptEn.CurrencyM105 = ""
Else
ManufacturingOrderReceiptEn.CurrencyM105 = objRec!CURRCOST
End If
objConn.Close
End Sub

Ensure that you add all fields you need to VB
Ensure you run GP as administrator or the VB will not save
Call this in the body to execute for each record
ManufacturingOrderReceiptEn.CurrencyM105 is an empty calculated field
You must put the calculated field in the BODY or the appropriate section where the VB code is running

No comments:

Post a Comment