*******************
iSQLCommandLen = Len(sSQLCommand)
iRC = SQLExecDirect(hstmt, sSQLCommand, iSQLCommandLen)
If iRC <> SQL_SUCCESS Then
MsgBox ("Unable to execute statement")
DescribeError henv, hstmt
End
End If
iRC = SQLNumResultCols(hstmt, iNumCols)
If iRC <> SQL_SUCCESS Then
MsgBox ("Unable to retrieve column count")
End
End If
iRow = 7
iRange_Start = 7
Do While SQLFetch(hstmt) = SQL_SUCCESS
sBuff = String$(255, 0)
For I = 1 To iNumCols
iRC = SQLGetData(hstmt, I, SQL_CHAR, ByVal sBuff, 255,
lOutlen)
If iRC <> SQL_SUCCESS Then
DescribeError hdbc, hstmt
End
End If
Select Case I
'Test to see if account number has changed, if so , do
subtotals
Case 1
If sSave_Acct <> Left$(sBuff, lOutlen) Then
If iRow <> 7 Then
Insert_Totals iRow, iRange_Start, iRow - 1
iRow = iRow + 2
sSave_Acct = Left$(sBuff, lOutlen)
iRange_Start = iRow
End If
sSave_Acct = Left$(sBuff, lOutlen)
bPrint_Acct = 1
End If
'Test for "print flag" - if so, print account number
Case 3, 4, 5
If bPrint_Acct = 1 Then
Sheets("Query_Result").Cells(iRow, I - 2).Value =
Left$(sBuff, lOutlen)
End If
If I = 5 Then
'Get the account description and increment the row
counter
'***************************************************************
sQueryString = "SELECT account_description FROM
FINANCIAL.dbo.glchart WHERE account_code = " + sSave_Acct
iSQLQueryLen = Len(sQueryString)
'Execute the query on the database
iRC = SQLExecDirect(hacc_desc, sQueryString,
iSQLQueryLen)
If iRC <> SQL_SUCCESS Then
MsgBox ("Unable to execute statement")
DescribeError henv, hstmt
End
End If
'Fetch the data
SQLFetch (hacc_desc)
iRC = SQLGetData(hacc_desc, 1, SQL_CHAR, ByVal
sBuff, 255, lOutlen)
If iRC <> SQL_SUCCESS Then
DescribeError hdbc, hstmt
End
End If
iRC = SQLFreeStmt(hacc_desc, SQL_CLOSE)
'Put the data in the sheet
Sheets("Query_Result").Cells(iRow, I - 1).Value =
Left$(sBuff, lOutlen)
iRow = iRow + 1
'***************************************************************
bPrint_Acct = 0
End If
'Check for matching GST and JCN entries, print on same
line
Case 2
If (Left$(sBuff, 3) = "JCN") Then
If (Mid$(sBuff, 4, 6) = Mid$(sSave_Doc, 4, 6))
Then
iRow = iRow - 1
End If
End If
sSave_Doc = Left$(sBuff, lOutlen)
Sheets("Query_Result").Cells(iRow, 10).Value =
Left$(sBuff, lOutlen)
'Put credits and debits in respective columns
Case 8
If Left$(sBuff, 1) = "-" Then
Sheets("Query_Result").Cells(iRow, 7).Value =
Left$(sBuff, lOutlen)
Else
Sheets("Query_Result").Cells(iRow, 6).Value =
Left$(sBuff, lOutlen)
End If
Sheets("Query_Result").Cells(iRow, 8).Value = _
Sheets("Query_Result").Cells(iRow, 6).Value -
Sheets("Query_Result").Cells(iRow, 7).Value
Case 9
Sheets("Query_Result").Cells(iRow, 9).Value =
Left$(sBuff, lOutlen)
Case Else
Sheets("Query_Result").Cells(iRow, I - 2).Value =
Left$(sBuff, lOutlen)
End Select
Next I
iRow = iRow + 1
Loop
Insert_Totals iRow, iRange_Start, iRow - 1
iRC = SQLFreeStmt(hstmt, SQL_DROP)
iRC = SQLFreeStmt(hacc_desc, SQL_DROP)
Format_Report
End Sub
*******************************************
* David Lawrence
*******************************************