• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

VBA SQL Query to return calculation

Shaun

Member
Hi All,

I have recorded an SQL Query which I would like to amend to include a calculation where two columns in the table are multiplied.

The query:
Code:
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array(Array( _
  "ODBC;DSN=MS Access Database;DBQ=" & fpth & ";DefaultDir=" & fdir & ";DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;" _
  )), Destination:=Range("$A$5")).QueryTable
  .CommandText = Array( _
  "SELECT MYOX_JournalTransactionLines.AccountUID, MYOX_JournalTransactionLines.AccountNumber, MYOX_Accounts.Type, MYOX_JournalTransactionLines.AccountName, MYOX_JournalTransactions.DateOccurred, MYOX_Jo" _
  , _
  "urnalTransactionLines.Amount, MYOX_JournalTransactionLines.IsCredit, MYOX_JournalTransactionLines.JobNumber" & Chr(13) & "" & Chr(10) & "FROM MYOX_Accounts MYOX_Accounts, MYOX_JournalTransactionLines MYOX_JournalTransactionLines" _
  , _
  ", MYOX_JournalTransactions MYOX_JournalTransactions" & Chr(13) & "" & Chr(10) & "WHERE MYOX_Accounts.AccountUID = MYOX_JournalTransactionLines.AccountUID AND MYOX_JournalTransactions.JournalTransactionUID = MYOX_JournalTransacti" _
  , "onLines.JournalTransactionUID")
  .RowNumbers = False
  .FillAdjacentFormulas = False
  .PreserveFormatting = True
  .RefreshOnFileOpen = False
  .BackgroundQuery = True
  .RefreshStyle = xlInsertDeleteCells
  .SavePassword = False
  .SaveData = True
  .AdjustColumnWidth = True
  .RefreshPeriod = 0
  .PreserveColumnInfo = True
  .ListObject.DisplayName = "Data"
  .Refresh BackgroundQuery:=False
  End With

I would like to multiply
Code:
MYOX_JournalTransactionLines.Amount
by
Code:
MYOX_JournalTransactionLines.IsCredit
with the result of the multiplication being returned as a series of positive and negatives values instead of both columns

Is anyone familiar with how this could be accomplished?

Cheers

Shaun
 

Attachments

  • MYOX_JournalTransactionLines.xlsx
    122 KB · Views: 2
Back
Top