Private Sub cmdTest_Click()
On Error GoTo ErrorHandler
Dim vCompany As SAPbobsCOM.Company
'create company object
Set vCompany = New SAPbobsCOM.Company
'set paras for connection
vCompany.CompanyDB = "SBODemo_US"
vCompany.Password = "manager"
vCompany.UserName = "manager"
vCompany.Server = "(local)"
'connect to database server
If (0 <> vCompany.Connect()) Then
MsgBox "Failed to connect"
Exit Sub
End If
'do it now
Call vCompany.StartTransaction
Dim vItm As SAPbobsCOM.Items
Set vItm = vCompany.GetBusinessObject(oItems)
Dim nReturn As Boolean
nReturn = vItm.GetByKey("M888")
If (nReturn = True) Then
vItm.BarCode = "1234567"
Call vItm.Update
End If
'Check Error
Dim nErr As Long
Dim errMsg As String
Call vCompany.GetLastError(nErr, errMsg)
If (0 <> nErr) Then
MsgBox ("Found error, code=" + Str(nErr) + ",msg=" + errMsg)
End If
Call vCompany.EndTransaction(wf_Commit)
'disconnect the company object, and release resource
Call vCompany.Disconnect
Set vCompany = Nothing
Exit Sub
ErrorHandler:
MsgBox ("Exception:" + Err.Description)
End Sub