Dim RS As ADODB.Recordset, sql As String
Dim topCell As Range
Dim meterID As String, product As String, rowOfs As Integer, i As Integer
Dim targetRef As String, targetCell As Range
Dim isclosingtankLevel As Integer
Dim cn As New ADODB.Connection, cmd As New ADODB.Command

sql = "SELECT production_month, tank_meter_id, product_id, sum(net_volume) as net_volume FROM v_common_daily_inventory " _
& "where (production_month = " & SEM_FormatOracleDate(startmonth - 1) & " " _
& "OR production_month = " & SEM_FormatOracleDate(endmonth - 1) & ") " _
& "GROUP BY production_month, tank_meter_id, product_id"

Set topCell = Range("TankMeters").Cells(1, 1)

cn.ConnectionString = SEM_GetIPSConnection()
cn.Properties("Prompt") = adPromptNever
cn.Open
cmd.ActiveConnection = cn
cmd.CommandText = sql
Set RS = cmd.Execute()

I'm getting an error on the red line
Run-time error '-2147217900 (80040e14)':
ORA-00904: "PRODUCTION_MONTH": invalid identifier

anyone know what the problem might be?

this is the SEM_FormatOracleDate function:
Function SEM_FormatOracleDate(dat As Date) As String
' Format the given date (and possibly time) using the required date format for Oracle SQL statements.

If dat = Fix(dat) Then
SEM_FormatOracleDate = "'" & Format$(dat, "dd-mmm-yyyy") & "'"
Else
SEM_FormatOracleDate = "'" & Format$(dat, "dd-mmm-yyyy Hh:Nn:Ss AMPM") & "'"
End If

End Function