Hello all,
I've been reading (lurking) these boards for a while now - all help so far has been much appreciated however, I now need something that I couldn't already find! I have been given an SQL query and asked if I can pull this data into Excel rather than having to use SQL Dev and emailing it manually every day.
I have pasted my code below, when running the query within vba I am seeing an error "SQL command not properly ended". Many thanks for any help in advance (connection details changed).
Sub Label()
Dim Cnn As Object
Set Cnn = CreateObject("ADODB.Connection")
Dim rst As Object
Set rst = CreateObject("ADODB.Recordset")
Dim ConnectionString As String
Dim StrQuery As String
ConnectionString = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=111.11.11.1)(PORT=1111))" & _
"(CONNECT_DATA=(SERVICE_NAME=RTCIS))); uid=1111_ro;pwd=1111;"
StrQuery = ""
StrQuery = StrQuery & "select subsit, arecod, locatn, serflg, fulflg, height, width, depth " & vbCrLf
StrQuery = StrQuery & "from locatn " & vbCrLf
StrQuery = StrQuery & "where arecod = 'RO' and not exists " & vbCrLf
StrQuery = StrQuery & "(select 'TRUE' from unitld " & vbCrLf
StrQuery = StrQuery & " where locatn.subsit = unitld.subsit and locatn.locatn = unitld.locatn) " & vbCrLf
StrQuery = StrQuery & "and (subsit like '&&subsit' or upper ('&&subsit') = 'ALL') " & vbCrLf
StrQuery = StrQuery & "order by subsit, arecod, locatn.locatn;"
Cnn.Open ConnectionString
Cnn.CommandTimeout = 900
rst.Open StrQuery, Cnn
Sheets(1).Range("A2").CopyFromRecordset rst
End Sub
I've been reading (lurking) these boards for a while now - all help so far has been much appreciated however, I now need something that I couldn't already find! I have been given an SQL query and asked if I can pull this data into Excel rather than having to use SQL Dev and emailing it manually every day.
I have pasted my code below, when running the query within vba I am seeing an error "SQL command not properly ended". Many thanks for any help in advance (connection details changed).
Sub Label()
Dim Cnn As Object
Set Cnn = CreateObject("ADODB.Connection")
Dim rst As Object
Set rst = CreateObject("ADODB.Recordset")
Dim ConnectionString As String
Dim StrQuery As String
ConnectionString = "Driver={Microsoft ODBC for Oracle}; " & _
"CONNECTSTRING=(DESCRIPTION=" & _
"(ADDRESS=(PROTOCOL=TCP)" & _
"(HOST=111.11.11.1)(PORT=1111))" & _
"(CONNECT_DATA=(SERVICE_NAME=RTCIS))); uid=1111_ro;pwd=1111;"
StrQuery = ""
StrQuery = StrQuery & "select subsit, arecod, locatn, serflg, fulflg, height, width, depth " & vbCrLf
StrQuery = StrQuery & "from locatn " & vbCrLf
StrQuery = StrQuery & "where arecod = 'RO' and not exists " & vbCrLf
StrQuery = StrQuery & "(select 'TRUE' from unitld " & vbCrLf
StrQuery = StrQuery & " where locatn.subsit = unitld.subsit and locatn.locatn = unitld.locatn) " & vbCrLf
StrQuery = StrQuery & "and (subsit like '&&subsit' or upper ('&&subsit') = 'ALL') " & vbCrLf
StrQuery = StrQuery & "order by subsit, arecod, locatn.locatn;"
Cnn.Open ConnectionString
Cnn.CommandTimeout = 900
rst.Open StrQuery, Cnn
Sheets(1).Range("A2").CopyFromRecordset rst
End Sub