Having a problem with VBA. I have written sql code (300 lines) which works perfect in SQL giving output:
Line Number Date Employee PN Tax
1 1111 2015-10-15 AP 6225-6 L1
2 1111 2015-10-15 AP 6225-6 L2
3 1111 2015-10-15 (null) CHARGE (null)
4 1111 2015-10-15 AP 55555 L2
I have inserted that big sql into my VBA code and for some reason it does not match precisely what i see in ORACLE.
What i see in VBA is this(different 3rd line):
Line Number Date Employee PN Tax
1 1111 2015-10-15 AP 6225-6 L1
2 1111 2015-10-15 AP 6225-6 L2
3 1111 (null) (null) 6225 (null)
4 1111 2015-10-15 AP 55555 L2
For some reason and somehow SQL work diferently and does not give desired output in VBA. What can cause this problem??? Having no clue, as i wrote twice SQL into VBA in case thought there was my mistake.
My VBA code:
Sub Update_table_and_data()
'sql failo suformavimas
Dim con As ADODB.Connection
Dim rec As ADODB.Recordset
Dim cmd As ADODB.Command
Dim sql As String
sql = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST= ODB)(PORT=1525))" & _
"(CONNECT_DATA=(SERVICE_NAME=ABTL))); uid=ID; pwd=PWD;"
dat1 = (Sheets("Data").Cells(2, "G"))
dat2 = (Sheets("Data").Cells(2, "H"))
Set con = New ADODB.Connection
Set rec = New ADODB.Recordset
Set cmd = New ADODB.Command
Sheets("Output").Range("A2:AS999999").ClearContents
If ((Not IsEmpty(dat1)) And (Not IsEmpty(dat2))) Then
con.Open sql
Set rec = con.Execute(" SELECT distinct ........
' " WHERE i.date >= to_date('" & dat1 & "','YYYY.MM.DD')
' " AND i.date <= to_date('" & dat2 & "','YYYY.MM.DD' ) ) XX order by XX.number ")
If Not rec.EOF Then
Sheets("Output").Range("A2").CopyFromRecordset rec
rec.Close
Else
MsgBox "PLEASE, CHECK DATE FORMAT!", vbCritical
End If
If CBool(con.State And adStateOpen) Then con.Close
Set rec = Nothing
Set con = Nothing
End Sub