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!

Account does not exist in Accpac General Ledger error

Status
Not open for further replies.

multisoft

Technical User
Dec 17, 2003
8
NG
Hi
I needed to write code to create and import batches into ACCPAC GL. My program is to read data from a file generated by an external program. The external file contains the necessary header and detail information. So I used the Macro recording tool of Accpac to create a macro for making entries and then modified what i got. However the amended macro by me created the batches but would not add detail lines and returns an error of "Internal error, Account does not exist in Accpac General Ledger", despite the existence of the account numbers. Below is the main part of the program.Can anyone be of help ?

Felix
multisoft

Sub MainSub()

On Error GoTo ACCPACErrorHandler

Dim mDBLinkCmpRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkCmpRW = OpenDBLink(DBLINK_COMPANY, DBLINK_FLG_READWRITE)

Dim mDBLinkSysRW As AccpacCOMAPI.AccpacDBLink
Set mDBLinkSysRW = OpenDBLink(DBLINK_SYSTEM, DBLINK_FLG_READWRITE)

Dim GLBATCH1batch As AccpacCOMAPI.AccpacView
Dim GLBATCH1batchFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "GL0008", GLBATCH1batch
Set GLBATCH1batchFields = GLBATCH1batch.Fields

Dim GLBATCH1header As AccpacCOMAPI.AccpacView
Dim GLBATCH1headerFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "GL0006", GLBATCH1header
Set GLBATCH1headerFields = GLBATCH1header.Fields

Dim GLBATCH1detail As AccpacCOMAPI.AccpacView
Dim GLBATCH1detailFields As AccpacCOMAPI.AccpacViewFields
mDBLinkCmpRW.OpenView "GL0010", GLBATCH1detail
Set GLBATCH1detailFields = GLBATCH1detail.Fields

GLBATCH1batch.Compose Array(GLBATCH1header)

GLBATCH1header.Compose Array(GLBATCH1batch, GLBATCH1detail)

GLBATCH1detail.Compose Array(GLBATCH1header)

'this routine gets the last batch
Dim strNewBatchID As String
Dim LastJournalid As String
Dim intCounter As Integer
GLBATCH1batch.Browse "", True
'show file dialog
frmFileInput.Show vbModal
'insert code here to extract file

'extract data from file
'get header info first
If strFileName <> &quot;&quot; Then

If Not GetBatchHeaders Then Exit Sub

If Not GetDetailHeaders Then Exit Sub

End If

'initialise headers
GLBATCH1batch.Browse &quot;((BATCHSTAT = &quot;&quot;1&quot;&quot; OR BATCHSTAT = &quot;&quot;6&quot;&quot; OR BATCHSTAT = &quot;&quot;9&quot;&quot;))&quot;, 1
GLBATCH1batchFields(&quot;BATCHID&quot;).Value = &quot;&quot;

GLBATCH1batch.Init 'creates a new batch number
GLBATCH1batch.Read
GLBATCH1headerFields(&quot;BTCHENTRY&quot;).Value = &quot;00000&quot;
GLBATCH1header.Browse &quot;&quot;, 1
GLBATCH1header.Fetch

GLBATCH1batchFields(&quot;BTCHDESC&quot;).PutWithoutVerification (&quot;Rollcall&quot;)
GLBATCH1batch.Update

With GLBATCH1batch
.GoBottom
strNewBatchID = Str(Val(GLBATCH1batch.Fields(&quot;BATCHID&quot;).Value))
End With

'then get remaining data
Dim intTransId As Integer
intTransId = 0
intCounter = 3
While ReadData
intCounter = 3

If strData(1) = &quot;1&quot; Then 'it is header info
GLBATCH1headerFields(&quot;BATCHID&quot;).PutWithoutVerification (strNewBatchID)
GLBATCH1headerFields(&quot;BTCHENTRY&quot;).Value = &quot;00000&quot;
GLBATCH1header.Init 'creates a new header

'initialise detail this should be part of the header creation
'but loop for every new header
GLBATCH1detail.Browse &quot;&quot;, 1
GLBATCH1detail.Fetch

GLBATCH1detailFields(&quot;BATCHNBR&quot;).PutWithoutVerification (strNewBatchID)
GLBATCH1detailFields(&quot;JOURNALID&quot;).PutWithoutVerification (&quot;00001&quot;)
'the following is the transaction number for the next transaction
GLBATCH1detailFields(&quot;TRANSNBR&quot;).PutWithoutVerification (&quot;-0000000000&quot;)

While strBatchHeader(intCounter) <> &quot;SRCETYPE&quot; And strBatchHeader(intCounter) <> &quot;&quot;
'batch header info
'GLBATCH1headerFields(strBatchHeader(intCounter)).Value = strData(intCounter)
intCounter = intCounter + 1
Wend
If strBatchHeader(intCounter) <> &quot;SRCETYPE&quot; Then
GLBATCH1headerFields(&quot;SRCETYPE&quot;).Value = &quot;JE&quot; 'assume journal entry for source type
Else
GLBATCH1headerFields(&quot;SRCETYPE&quot;).Value = strData(intCounter)
End If


Else

GLBATCH1detail.Init
intCounter = 3
While strBatchHeader(intCounter) <> &quot;&quot;
'this part creates additional detail lines

GLBATCH1detailFields(strDetailHeader(intCounter)).Value = strData(intCounter)
intCounter = intCounter + 1
Wend
'the following is the transaction number specified earlier
If intTransId > 0 Then
GLBATCH1detailFields(&quot;TRANSNBR&quot;).PutWithoutVerification (Format(intTransId, &quot;-0#########&quot;)) ' Transaction Number
End If
intTransId = intTransId + 1

GLBATCH1detail.Insert
GLBATCH1detail.Browse &quot;&quot;, 1

If intTransId > 0 Then
GLBATCH1detailFields(&quot;TRANSNBR&quot;).PutWithoutVerification (Format(intTransId, &quot;-0#########&quot;)) ' Transaction Number
End If

GLBATCH1detail.Read

End If
Wend


Exit Sub

ACCPACErrorHandler:
Dim lCount As Long
Dim lIndex As Long

If Errors Is Nothing Then
MsgBox Err.Description
MsgBox &quot;VBA Macros cannot run where Accpac is deployed as a Web Server&quot;
Else
lCount = Errors.Count

If lCount = 0 Then
MsgBox Err.Description
Else
For lIndex = 0 To lCount - 1
MsgBox Errors.Item(lIndex)
Next
Errors.Clear
End If
Resume Next

End If

End Sub




 
Actually, based on the code above the error is really easy to decipher - you've never actually put anything into the ACCTID field. :)

I'd go back to your macro recording as you've left out some of the original code. You're missing some code between GLBATCH1detail.Init and GLBATCH1detail.Insert.



Also - as a side note, when you retrived the batch number:

GLBATCH1batch.Browse &quot;((BATCHSTAT = &quot;&quot;1&quot;&quot; OR BATCHSTAT = &quot;&quot;6&quot;&quot; OR BATCHSTAT = &quot;&quot;9&quot;&quot;))&quot;, 1
GLBATCH1batchFields(&quot;BATCHID&quot;).Value = &quot;&quot;

GLBATCH1batch.Init 'creates a new batch number
GLBATCH1batch.Read
GLBATCH1headerFields(&quot;BTCHENTRY&quot;).Value = &quot;00000&quot;
GLBATCH1header.Browse &quot;&quot;, 1
GLBATCH1header.Fetch
GLBATCH1batchFields(&quot;BTCHDESC&quot;).PutWithoutVerification (&quot;Rollcall&quot;)
GLBATCH1batch.Update

With GLBATCH1batch
.GoBottom
strNewBatchID = Str(Val(GLBATCH1batch.Fields(&quot;BATCHID&quot;).Value))
End With


You can simplify your code and make it more multi-user friendly like this:

[tt]
GLBATCH1batch.Fields(&quot;BATCHID&quot;).Value = &quot;00000&quot;
GLBATCH1batch.INIT
strNewBatchID = GLBATCH1batch.Fields(&quot;BATCHID&quot;).Value
[/tt]

You can read the batch number from the view right after calling init. It's safer to but &quot;00000&quot; in the BATCHID before calling .init incase your macro needs to create multiple batches. If you use the .GoToBottom command in the way you have you leave open the possibility that someone else could generate a new batch after you do but before your code runs .GoToBottom.

Good luck!

Djangman
 
Hi Djangman,

I must thank you immensely for taking your time to response to my mail. Your Tips gave me a better insite on how to solve the problem. After a couple of false starts, it finally worked. You are just awesome !

I also need to import the AR invoices. I hope I can figure that out on my own ! I do have problems I will come calling.

Again, thank you

Felix
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top