Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Error in trying to insert a customer 1

Status
Not open for further replies.

BallpointPenguin

Programmer
Oct 23, 2007
12
US
Code:
[green]'... Dimension variables ...[/green]
Dim Session As New AccpacSession
Dim dblink As AccpacDBLink
Dim ovarcustomer as AccpacView
Dim ovARCUSO as AccpacView
Dim ary5a(0) as AccpacView
Dim ary5b(0) as AccpacView
Dim llngSuccess as Long
Dim lbolTemp as Boolean
Const ACCPACuid as String = "" [green]'fill with user ID[/green]
Const ACCPACpwd as String = "" [green]'fill with password[/green]
Const ACCPACcomp as String = "" [green]'fill with company name[/green]

[green]'... Set up connection to ACCPAC ...[/green]
Session.Init("", "CS", "CS0001", "54")
Session.Open(ACCPACuid, ACCPACpwd, ACCPACcomp, Now, 0, "")
If Not Session.IsOpened Then End Sub
dblink = Session.OpenDBLink(tagDBLinkTypeEnum.DBLINK_COMPANY, tagDBLinkFlagsEnum.DBLINK_FLG_READWRITE)

[green]'... Set up ACCPAC views ...[/green]
llngSuccess = dblink.OpenView("AR0024", ovarcustomer)
ary5a(0) = ovarcustomer
llngSuccess = dblink.OpenView("AR0400", ovARCUSO)
ary5b(0) = ovARCUSO
ovarcustomer.Compose(ary5b)
ovARCUSO.Compose(ary5a)
ovarcustomer.SystemAccess = AccpacCOMAPI.tagSystemAccessEnum.VIEW_SYSACCS_POSTING
ovARCUSO.SystemAccess = AccpacCOMAPI.tagSystemAccessEnum.VIEW_SYSACCS_POSTING


[green]'... Initialize views for customer creation ...[/green]
ovarcustomer.Init()
ovARCUSO.Init()

With ovarcustomer.fields
	.FieldByName("idcust").Value = Me.CustomerID
	lbolTemp = oSys.arcustomer.Exists()
	oSys.arcustomer.Process()
	.FieldByName("namecust").Value = Me.Bilname.Trim
	[green]'... fill in with other fields ...[/green]
End With
ovarcustomer.Process()
ovarcustomer.Insert()
.
.
.

When I run this code while trying to programmatically (I hope that's spelled right!) enter a customer, I always wind up getting a "Record Already Exists" error from Accpac on the Insert command.

The customer code that I'm generating is a unique value, and I've been R'ing the FM's pretty hard. However, I'm afraid that there's something about this that I'm not quite getting, so I'm asking for help.

Again, I'm sure that it's just a single-line command of some sort, or a mis-typed command. Could anyone please help me understand what I'm overlooking?

Thanks!

John Gardner
 
If you're just adding a customer, you shouldn't need ovarcustomer.Process(), that's usually for optional fields. I would only have a .Insert.

And you can take out all the

lbolTemp = oSys.arcustomer.Exists()

statements, that's just dirt from the recording process.
 
Well, I think I found what was causing the "record already exists" error. That was the fact that I was looking at one table for generating a unique customer ID, and that table hadn't been updated with the last created record, so that complicated matters. Once I got everything synchronized, that seems to determined that matter.

Now, though, the error I get on the insert command is this:

SageCRM Connection Failed. System error. Cannot log in to SageCRM web server. Error returned: Logon ERROR:ActiveX component can't create object

Again, is it something simple that I'm missing?
 
Your problem is related to the environment where you are running your VB.Net code.

The error message is indicating that the syncronization component for CRM is trying to open up and sync your changes to the CRM database. For some environmental reason, the CRM sync component is unable to run.

I suspect you'll find that your new customer is created in Accpac but not in CRM.

Wherever your code is running, install the Accpac client and make sure that it can run and update customers properly without the CRM sync component failing. That should fix this error.

Hope that helps,
Chris Zinck, P.Eng.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top