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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XAPI journal entry posting

Status
Not open for further replies.

troyddaniels

Programmer
Jan 11, 2007
28
US
I'm writing a program that will create journal entries from a spreadsheet embedded in a VB6 application. Here is the code I've pretty much copied as verbatum as possible from a macro I recorded in Accpac. But it get's hung up when calling up GLbatchDetailFields("ACCTID") = xxxxx. I get a "view call failed" error. Can anyone tell me what I need to change in this code to get it to start assigning my values to the fields so that I can get it to create the batch entry? Thanks.


Dim session As ACCPACXAPILib.xapiSession
Set session = CreateObject("Accpac.xapisession")
session.Open "ADMIN", "ADMIN", "TWOCOM", Date, 0

Dim GLbatch As ACCPACXAPILib.xapiView
Dim GLbatchFields As ACCPACXAPILib.xapiFields
Set GLbatch = session.OpenView("GL0008", "GL")
Set GLbatchFields = GLbatch.Fields


Dim GLbatchHeader As ACCPACXAPILib.xapiView
Dim GLbatchHeaderFields As ACCPACXAPILib.xapiFields
Set GLbatchHeader = session.OpenView("GL0006", "GL")
Set GLbatchHeaderFields = GLbatchHeader.Fields

Dim GLbatchDetail As ACCPACXAPILib.xapiView
Dim GLbatchDetailFields As ACCPACXAPILib.xapiFields
Set GLbatchDetail = session.OpenView("GL0010", "GL")
Set GLbatchDetailFields = GLbatchDetail.Fields

Dim GLbatchDetail2 As ACCPACXAPILib.xapiView
Dim GLbatchDetail2Fields As ACCPACXAPILib.xapiFields
Set GLbatchDetail2 = session.OpenView("GL0402", "GL")
Set GLbatchDetail2Fields = GLbatchDetail2.Fields

GLbatch.Compose Array(GLbatchHeader)
GLbatchHeader.Compose Array(GLbatch, GLbatchDetail)
GLbatchDetail.Compose Array(GLheader, GLbatchDetail2)
GLbatchDetail2.Compose Array(GLDetail)

X = 2

GLbatch.Browse "((Batchstat = ""1"" or batchstat = ""6"" or batchstat = ""9""))", 1

GLbatch.Init
GLbatch.Read
GLbatchHeaderFields("Btchendtry").PutWithoutVerification ("")
GLbatchHeader.Browse "", 1
GLbatchHeader.Fetch

GLbatchHeaderFields("BTchentry").PutWithoutVerification (BatchLabel.Caption)
GLbatch.Update
GLbatchHeaderFields("DATEENTRY").Value = BatchSS.Range("B" & X)
GLbatchHeaderFields("SRCETYPE") = SourceCombo.Text

If reverseCheck.Value = True Then
GLbatchHeaderFields("SWREVERSE").PutWithoutVerification ("1")
End If
'debit side
GLbatchDetail.RecordClear
GLbatchDetail.RecordGenerate False

GLbatchDetailFields("ACCTID") = BatchSS.Range("E" & X)
GLbatchDetailFields("SCURNAMT") = BatchSS.Range("D" & X)
GLbatchDetailFields("TRANSREF") = BatchSS.Range("A" & X)
GLbatchDetailFields("TRANSEDESC") = BatchSS.Range("C" & X)
GLbatchDetail.Insert
GLbatchDetail.Fields("TRANSNBR").PutWithoutVerification (X)

GLbatchDetail.Read
GLbatchDetail.RecordGenerate False

GLbatchDetailFields("ACCTID") = BatchSS.Range("E" & X)
GLbatchDetailFields("SCURNAMT") = BatchSS.Range("D" & X) * -1
GLbatchDetailFields("TRANSREF") = BatchSS.Range("A" & X)
GLbatchDetailFields("TRANSEDESC") = BatchSS.Range("C" & X)
GLbatchDetail.Insert
GLbatchDetail.Fields("TRANSNBR").PutWithoutVerification (X)
GLbatchDetail.Read

GLbatchHeaderFields("JRNLDESC").PutWithoutVerification (BatchLabel.Caption)

GLbatchHeader.Insert
GLbatchHeader.Read
GLbatchHeader.Update
 
Check the Session.Error object when it fails, it should give you more messages.

Jay Converse
IT Director
Systemlink, Inc.
 
Make sure that the value from the excel cell is being interpreted as a string. You may have to explicitly set it to a string type with the str() function.

zemp
 
I tried setting it to a string, same error. If I take off the accpac error handling I get an error message "run time error '-2147467259 (80004005)': view call failed". If I include the error handler I get a 'the "session" object was not opened.' error.

You know what the worst part of this is, is I'm going to spend hours going at this and in the end it is going to turn out to be some little obvious typo or something.

Anyway thanks for your input so far, if anyone has anything else that might help it would be greatly appreciated.
 
I ran your code down to this line:

GLbatchDetailFields("ACCTID") = BatchSS.Range("E" & X)

where I change BatchSS.Range to "1000", since I don't have your data. I got an error message, then typed this into the immediate window:

? SESSION.Errors(SESSION.Errors.Count-1)

and got this result:

Journal Detail
Attempt to change read-only field 'Account Number'.

So your code looks fine. Maybe you should record a macro to see how Accpac does it.

Jay Converse
IT Director
Systemlink, Inc.
 
This is a shot in the dark, but try setting the header source ledger (SRCELEDGER - check the field name) field.
 
Thanks guys, I ran the accpac macro again then copied it straight over and converted it to xapi rather than writing the xapi and then copying the code over. I must've missed something the first time I copied it over because now it works fine. Thank for your time and help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top