Hi there, I'm trying to update Accpac view from my VB .NET code but seem to be getting an error : Error HRESULT E_FAIL has been returned from a call to a COM component. This error appears on the ARCUSTOMER51header.Update() statement. I'm not sure what i'm doing wrong here. Please help. Below is my code :
Imports System
Imports System.IO
'Imports Microsoft.SqlServer.Management.Common
'Imports Microsoft.SqlServer.Management.Smo
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports ACCPAC.Advantage
Public Class Form1
Public session As Session = Nothing
Public mDBLinkCmpRW As DBLink = Nothing
Dim ARCUSTOMER51header As ACCPAC.Advantage.View
Dim ARCUSTOMER51headerFields As ACCPAC.Advantage.ViewFields
Dim ARCUSTOMER51detail As ACCPAC.Advantage.View
Dim ARCUSTOMER51detailFields As ACCPAC.Advantage.ViewFields
Dim ARCUSTSTAT52 As ACCPAC.Advantage.View
Dim ARCUSTSTAT52Fields As ACCPAC.Advantage.ViewFields
Dim ARCUSTCMT3 As ACCPAC.Advantage.View
Dim ARCUSTCMT3Fields As ACCPAC.Advantage.ViewFields
Public Sub InitializeDBLink()
mDBLinkCmpRW = session.OpenDBLink(DBLinkType.Company, DBLinkFlags.ReadWrite)
End Sub
Public Sub OpenCustomer()
'ARCUSTOMER1header.Compose(New ACCPAC.Advantage.View() {ARCUSTOMER1header})
ARCUSTOMER51header = mDBLinkCmpRW.OpenView("AR0024")
ARCUSTOMER51headerFields = ARCUSTOMER51header.Fields
ARCUSTOMER51detail = mDBLinkCmpRW.OpenView("AR0400")
ARCUSTOMER51detailFields = ARCUSTOMER51detail.Fields
ARCUSTSTAT52 = mDBLinkCmpRW.OpenView("AR0022")
ARCUSTSTAT52Fields = ARCUSTSTAT52.Fields
ARCUSTCMT3 = mDBLinkCmpRW.OpenView("AR0021")
ARCUSTCMT3Fields = ARCUSTCMT3.Fields
'Dim vh As ACCPAC.Advantage.View() = {ARCUSTOMER1header}
'Dim vd As ACCPAC.Advantage.View() = {ARCUSTOMER1detail}
'ARCUSTOMER1header.Compose(vh)
'ARCUSTOMER1detail.Compose(vd)
End Sub
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
'Create session to accpac...
session = New Session()
'Initialise session and login...
session.Init("", "XX", "XX0001", "55")
session.Open("USER1", "ACCPAC", "CLDDAT", System.DateTime.Now, 0)
InitializeDBLink()
OpenCustomer()
Dim temp As Boolean
temp = ARCUSTSTAT52.Exists
ARCUSTSTAT52.Init()
ARCUSTSTAT52Fields.FieldByName("IDCUST").SetValue("TEST519", False) ' Customer Number
ARCUSTSTAT52Fields.FieldByName("CNTYR").SetValue("2010", False) ' Year
ARCUSTSTAT52Fields.FieldByName("CNTPERD").SetValue("03", False) ' Period
ARCUSTSTAT52Fields.FieldByName("YTDACTIVE").SetValue("1", False) ' Enable YTD Calculations
temp = ARCUSTOMER51header.Exists
ARCUSTOMER51header.Init()
temp = ARCUSTSTAT52.Exists
ARCUSTSTAT52.Init()
ARCUSTSTAT52Fields.FieldByName("CNTYR").SetValue("2010", False) ' Year
ARCUSTSTAT52Fields.FieldByName("CNTPERD").SetValue("03", False) ' Period
temp = ARCUSTOMER51header.Exists
ARCUSTOMER51header.Init()
temp = ARCUSTSTAT52.Exists
ARCUSTSTAT52.Init()
ARCUSTSTAT52Fields.FieldByName("CNTYR").SetValue("2010", False) ' Year
ARCUSTSTAT52Fields.FieldByName("CNTPERD").SetValue("03", False) ' Period
ARCUSTOMER51headerFields.FieldByName("IDCUST").SetValue("TEST519", False) ' Customer Number
temp = ARCUSTOMER51header.Exists
ARCUSTOMER51headerFields.FieldByName("NAMECUST").SetValue("This is a test customer 05", False) ' Customer Name
ARCUSTOMER51headerFields.FieldByName("IDGRP").SetValue("TEST", False) ' Group Code
ARCUSTOMER51headerFields.FieldByName("TEXTSNAM").SetValue("Test Short 05", False) ' Short Name
ARCUSTOMER51headerFields.FieldByName("TEXTSTRE1").SetValue("Line 1 05", False) ' Address Line 1
ARCUSTOMER51headerFields.FieldByName("TEXTSTRE2").SetValue("Line 2", False) ' Address Line 2
ARCUSTOMER51headerFields.FieldByName("TEXTSTRE3").SetValue("Line 3", False) ' Address Line 3
ARCUSTOMER51headerFields.FieldByName("TEXTSTRE4").SetValue("Line 4", False) ' Address Line 4
ARCUSTOMER51headerFields.FieldByName("NAMECITY").SetValue("City", False) ' City
ARCUSTOMER51headerFields.FieldByName("CODECTRY").SetValue("Country", False) ' Country
ARCUSTOMER51headerFields.FieldByName("CODESTTE").SetValue("Province", False) ' State/Prov.
ARCUSTOMER51headerFields.FieldByName("TEXTPHON1").SetValue("Telephone", False) ' Phone Number
ARCUSTOMER51headerFields.FieldByName("CODEPSTL").SetValue("Postal", False) ' Zip/Postal Code
ARCUSTOMER51headerFields.FieldByName("TEXTPHON2").SetValue("Fax", False) ' Fax Number
ARCUSTOMER51headerFields.FieldByName("EMAIL2").SetValue("E-Mail", False) ' E-mail
ARCUSTOMER51headerFields.FieldByName("WEBSITE").SetValue("Web", False) ' Web Site
ARCUSTOMER51headerFields.FieldByName("NAMECTAC").SetValue("Test", False) ' Contact Name
ARCUSTOMER51headerFields.FieldByName("CTACPHONE").SetValue("Contact Tel", False) ' Contact's Phone
ARCUSTOMER51headerFields.FieldByName("CTACFAX").SetValue("Contact Fax", False) ' Contact's Fax
ARCUSTOMER51headerFields.FieldByName("EMAIL1").SetValue("Contact E-mail", False) ' Contact's E-mail
ARCUSTOMER51headerFields.FieldByName("PAYMCODE").SetValue("EFT", False) ' Payment Code
ARCUSTOMER51headerFields.FieldByName("CODEDAB").SetValue("CR123", False) ' Credit Bureau Number
ARCUSTOMER51headerFields.FieldByName("CODEDABRTG").SetValue("1", False) ' Credit Bureau Rating
ARCUSTOMER51headerFields.FieldByName("DATEDAB").SetValue(DateTime.Now, False) ' Credit Bureau Date
ARCUSTOMER51headerFields.FieldByName("CODETAXGRP").SetValue("VAT", False) ' Tax Group
ARCUSTOMER51headerFields.FieldByName("CODESLSP1").SetValue("DEVRON", False) ' Salesperson code
ARCUSTOMER51header.Update()
'Else
' MessageBox.Show("Customer record Not Updated", "Click OK to continue", MessageBoxButtons.OK, _
' MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
'End If
Try
'Display a message that the record was added...
MessageBox.Show("Customer record Updated", "Click OK to continue", MessageBoxButtons.OK, _
MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Catch SqlExceptionErr As SqlException
MessageBox.Show("ACCPAR ERROR", "ACCPAC IE Customers", MessageBoxButtons.OK, _
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Try
DisposeConnection()
End Sub
Public Sub DisposeConnection()
mDBLinkCmpRW.Dispose()
session.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
Imports System
Imports System.IO
'Imports Microsoft.SqlServer.Management.Common
'Imports Microsoft.SqlServer.Management.Smo
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports ACCPAC.Advantage
Public Class Form1
Public session As Session = Nothing
Public mDBLinkCmpRW As DBLink = Nothing
Dim ARCUSTOMER51header As ACCPAC.Advantage.View
Dim ARCUSTOMER51headerFields As ACCPAC.Advantage.ViewFields
Dim ARCUSTOMER51detail As ACCPAC.Advantage.View
Dim ARCUSTOMER51detailFields As ACCPAC.Advantage.ViewFields
Dim ARCUSTSTAT52 As ACCPAC.Advantage.View
Dim ARCUSTSTAT52Fields As ACCPAC.Advantage.ViewFields
Dim ARCUSTCMT3 As ACCPAC.Advantage.View
Dim ARCUSTCMT3Fields As ACCPAC.Advantage.ViewFields
Public Sub InitializeDBLink()
mDBLinkCmpRW = session.OpenDBLink(DBLinkType.Company, DBLinkFlags.ReadWrite)
End Sub
Public Sub OpenCustomer()
'ARCUSTOMER1header.Compose(New ACCPAC.Advantage.View() {ARCUSTOMER1header})
ARCUSTOMER51header = mDBLinkCmpRW.OpenView("AR0024")
ARCUSTOMER51headerFields = ARCUSTOMER51header.Fields
ARCUSTOMER51detail = mDBLinkCmpRW.OpenView("AR0400")
ARCUSTOMER51detailFields = ARCUSTOMER51detail.Fields
ARCUSTSTAT52 = mDBLinkCmpRW.OpenView("AR0022")
ARCUSTSTAT52Fields = ARCUSTSTAT52.Fields
ARCUSTCMT3 = mDBLinkCmpRW.OpenView("AR0021")
ARCUSTCMT3Fields = ARCUSTCMT3.Fields
'Dim vh As ACCPAC.Advantage.View() = {ARCUSTOMER1header}
'Dim vd As ACCPAC.Advantage.View() = {ARCUSTOMER1detail}
'ARCUSTOMER1header.Compose(vh)
'ARCUSTOMER1detail.Compose(vd)
End Sub
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
'Create session to accpac...
session = New Session()
'Initialise session and login...
session.Init("", "XX", "XX0001", "55")
session.Open("USER1", "ACCPAC", "CLDDAT", System.DateTime.Now, 0)
InitializeDBLink()
OpenCustomer()
Dim temp As Boolean
temp = ARCUSTSTAT52.Exists
ARCUSTSTAT52.Init()
ARCUSTSTAT52Fields.FieldByName("IDCUST").SetValue("TEST519", False) ' Customer Number
ARCUSTSTAT52Fields.FieldByName("CNTYR").SetValue("2010", False) ' Year
ARCUSTSTAT52Fields.FieldByName("CNTPERD").SetValue("03", False) ' Period
ARCUSTSTAT52Fields.FieldByName("YTDACTIVE").SetValue("1", False) ' Enable YTD Calculations
temp = ARCUSTOMER51header.Exists
ARCUSTOMER51header.Init()
temp = ARCUSTSTAT52.Exists
ARCUSTSTAT52.Init()
ARCUSTSTAT52Fields.FieldByName("CNTYR").SetValue("2010", False) ' Year
ARCUSTSTAT52Fields.FieldByName("CNTPERD").SetValue("03", False) ' Period
temp = ARCUSTOMER51header.Exists
ARCUSTOMER51header.Init()
temp = ARCUSTSTAT52.Exists
ARCUSTSTAT52.Init()
ARCUSTSTAT52Fields.FieldByName("CNTYR").SetValue("2010", False) ' Year
ARCUSTSTAT52Fields.FieldByName("CNTPERD").SetValue("03", False) ' Period
ARCUSTOMER51headerFields.FieldByName("IDCUST").SetValue("TEST519", False) ' Customer Number
temp = ARCUSTOMER51header.Exists
ARCUSTOMER51headerFields.FieldByName("NAMECUST").SetValue("This is a test customer 05", False) ' Customer Name
ARCUSTOMER51headerFields.FieldByName("IDGRP").SetValue("TEST", False) ' Group Code
ARCUSTOMER51headerFields.FieldByName("TEXTSNAM").SetValue("Test Short 05", False) ' Short Name
ARCUSTOMER51headerFields.FieldByName("TEXTSTRE1").SetValue("Line 1 05", False) ' Address Line 1
ARCUSTOMER51headerFields.FieldByName("TEXTSTRE2").SetValue("Line 2", False) ' Address Line 2
ARCUSTOMER51headerFields.FieldByName("TEXTSTRE3").SetValue("Line 3", False) ' Address Line 3
ARCUSTOMER51headerFields.FieldByName("TEXTSTRE4").SetValue("Line 4", False) ' Address Line 4
ARCUSTOMER51headerFields.FieldByName("NAMECITY").SetValue("City", False) ' City
ARCUSTOMER51headerFields.FieldByName("CODECTRY").SetValue("Country", False) ' Country
ARCUSTOMER51headerFields.FieldByName("CODESTTE").SetValue("Province", False) ' State/Prov.
ARCUSTOMER51headerFields.FieldByName("TEXTPHON1").SetValue("Telephone", False) ' Phone Number
ARCUSTOMER51headerFields.FieldByName("CODEPSTL").SetValue("Postal", False) ' Zip/Postal Code
ARCUSTOMER51headerFields.FieldByName("TEXTPHON2").SetValue("Fax", False) ' Fax Number
ARCUSTOMER51headerFields.FieldByName("EMAIL2").SetValue("E-Mail", False) ' E-mail
ARCUSTOMER51headerFields.FieldByName("WEBSITE").SetValue("Web", False) ' Web Site
ARCUSTOMER51headerFields.FieldByName("NAMECTAC").SetValue("Test", False) ' Contact Name
ARCUSTOMER51headerFields.FieldByName("CTACPHONE").SetValue("Contact Tel", False) ' Contact's Phone
ARCUSTOMER51headerFields.FieldByName("CTACFAX").SetValue("Contact Fax", False) ' Contact's Fax
ARCUSTOMER51headerFields.FieldByName("EMAIL1").SetValue("Contact E-mail", False) ' Contact's E-mail
ARCUSTOMER51headerFields.FieldByName("PAYMCODE").SetValue("EFT", False) ' Payment Code
ARCUSTOMER51headerFields.FieldByName("CODEDAB").SetValue("CR123", False) ' Credit Bureau Number
ARCUSTOMER51headerFields.FieldByName("CODEDABRTG").SetValue("1", False) ' Credit Bureau Rating
ARCUSTOMER51headerFields.FieldByName("DATEDAB").SetValue(DateTime.Now, False) ' Credit Bureau Date
ARCUSTOMER51headerFields.FieldByName("CODETAXGRP").SetValue("VAT", False) ' Tax Group
ARCUSTOMER51headerFields.FieldByName("CODESLSP1").SetValue("DEVRON", False) ' Salesperson code
ARCUSTOMER51header.Update()
'Else
' MessageBox.Show("Customer record Not Updated", "Click OK to continue", MessageBoxButtons.OK, _
' MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
'End If
Try
'Display a message that the record was added...
MessageBox.Show("Customer record Updated", "Click OK to continue", MessageBoxButtons.OK, _
MessageBoxIcon.Information, MessageBoxDefaultButton.Button1)
Catch SqlExceptionErr As SqlException
MessageBox.Show("ACCPAR ERROR", "ACCPAC IE Customers", MessageBoxButtons.OK, _
MessageBoxIcon.Error, MessageBoxDefaultButton.Button1)
End Try
DisposeConnection()
End Sub
Public Sub DisposeConnection()
mDBLinkCmpRW.Dispose()
session.Dispose()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class