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 <> "" Then
If Not GetBatchHeaders Then Exit Sub
If Not GetDetailHeaders Then Exit Sub
End If
'initialise headers
GLBATCH1batch.Browse "((BATCHSTAT = ""1"" OR BATCHSTAT = ""6"" OR BATCHSTAT = ""9"")", 1
GLBATCH1batchFields("BATCHID".Value = ""
GLBATCH1batch.Init 'creates a new batch number
GLBATCH1batch.Read
GLBATCH1headerFields("BTCHENTRY".Value = "00000"
GLBATCH1header.Browse "", 1
GLBATCH1header.Fetch
GLBATCH1batchFields("BTCHDESC".PutWithoutVerification ("Rollcall"
GLBATCH1batch.Update
With GLBATCH1batch
.GoBottom
strNewBatchID = Str(Val(GLBATCH1batch.Fields("BATCHID".Value))
End With
'then get remaining data
Dim intTransId As Integer
intTransId = 0
intCounter = 3
While ReadData
intCounter = 3
If strData(1) = "1" Then 'it is header info
GLBATCH1headerFields("BATCHID".PutWithoutVerification (strNewBatchID)
GLBATCH1headerFields("BTCHENTRY".Value = "00000"
GLBATCH1header.Init 'creates a new header
'initialise detail this should be part of the header creation
'but loop for every new header
GLBATCH1detail.Browse "", 1
GLBATCH1detail.Fetch
GLBATCH1detailFields("BATCHNBR".PutWithoutVerification (strNewBatchID)
GLBATCH1detailFields("JOURNALID".PutWithoutVerification ("00001"
'the following is the transaction number for the next transaction
GLBATCH1detailFields("TRANSNBR".PutWithoutVerification ("-0000000000"
While strBatchHeader(intCounter) <> "SRCETYPE" And strBatchHeader(intCounter) <> ""
'batch header info
'GLBATCH1headerFields(strBatchHeader(intCounter)).Value = strData(intCounter)
intCounter = intCounter + 1
Wend
If strBatchHeader(intCounter) <> "SRCETYPE" Then
GLBATCH1headerFields("SRCETYPE".Value = "JE" 'assume journal entry for source type
Else
GLBATCH1headerFields("SRCETYPE".Value = strData(intCounter)
End If
Else
GLBATCH1detail.Init
intCounter = 3
While strBatchHeader(intCounter) <> ""
'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("TRANSNBR".PutWithoutVerification (Format(intTransId, "-0#########") ' Transaction Number
End If
intTransId = intTransId + 1
GLBATCH1detail.Insert
GLBATCH1detail.Browse "", 1
If intTransId > 0 Then
GLBATCH1detailFields("TRANSNBR".PutWithoutVerification (Format(intTransId, "-0#########") ' 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 "VBA Macros cannot run where Accpac is deployed as a Web Server"
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
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 <> "" Then
If Not GetBatchHeaders Then Exit Sub
If Not GetDetailHeaders Then Exit Sub
End If
'initialise headers
GLBATCH1batch.Browse "((BATCHSTAT = ""1"" OR BATCHSTAT = ""6"" OR BATCHSTAT = ""9"")", 1
GLBATCH1batchFields("BATCHID".Value = ""
GLBATCH1batch.Init 'creates a new batch number
GLBATCH1batch.Read
GLBATCH1headerFields("BTCHENTRY".Value = "00000"
GLBATCH1header.Browse "", 1
GLBATCH1header.Fetch
GLBATCH1batchFields("BTCHDESC".PutWithoutVerification ("Rollcall"
GLBATCH1batch.Update
With GLBATCH1batch
.GoBottom
strNewBatchID = Str(Val(GLBATCH1batch.Fields("BATCHID".Value))
End With
'then get remaining data
Dim intTransId As Integer
intTransId = 0
intCounter = 3
While ReadData
intCounter = 3
If strData(1) = "1" Then 'it is header info
GLBATCH1headerFields("BATCHID".PutWithoutVerification (strNewBatchID)
GLBATCH1headerFields("BTCHENTRY".Value = "00000"
GLBATCH1header.Init 'creates a new header
'initialise detail this should be part of the header creation
'but loop for every new header
GLBATCH1detail.Browse "", 1
GLBATCH1detail.Fetch
GLBATCH1detailFields("BATCHNBR".PutWithoutVerification (strNewBatchID)
GLBATCH1detailFields("JOURNALID".PutWithoutVerification ("00001"
'the following is the transaction number for the next transaction
GLBATCH1detailFields("TRANSNBR".PutWithoutVerification ("-0000000000"
While strBatchHeader(intCounter) <> "SRCETYPE" And strBatchHeader(intCounter) <> ""
'batch header info
'GLBATCH1headerFields(strBatchHeader(intCounter)).Value = strData(intCounter)
intCounter = intCounter + 1
Wend
If strBatchHeader(intCounter) <> "SRCETYPE" Then
GLBATCH1headerFields("SRCETYPE".Value = "JE" 'assume journal entry for source type
Else
GLBATCH1headerFields("SRCETYPE".Value = strData(intCounter)
End If
Else
GLBATCH1detail.Init
intCounter = 3
While strBatchHeader(intCounter) <> ""
'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("TRANSNBR".PutWithoutVerification (Format(intTransId, "-0#########") ' Transaction Number
End If
intTransId = intTransId + 1
GLBATCH1detail.Insert
GLBATCH1detail.Browse "", 1
If intTransId > 0 Then
GLBATCH1detailFields("TRANSNBR".PutWithoutVerification (Format(intTransId, "-0#########") ' 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 "VBA Macros cannot run where Accpac is deployed as a Web Server"
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