Function GetPastDueRQ(sPN As String, Optional sNG As String = "") As Integer
Dim sConn As String, sSQL As String, sServer As String
Dim rst As ADODB.Recordset, cnn As ADODB.Connection[b]
Dim fld as ADODB.Field, iCol as integer, lRow as long[/b]
Set cnn = New ADODB.Connection
sServer = "sdeloophole"
cnn.Open "Driver={Microsoft ODBC for Oracle};" & _
"Server=" & sServer & ";" & _
"Uid=Myusername;" & _
"Pwd=MyPassword"
'M5C9861BL
'CAL0002
Set rst = New ADODB.Recordset
sSQL = "SELECT C_MATRIX "
sSQL = sSQL & "FROM REPORTING_VW "
sSQL = sSQL & "WHERE ROUTE_CODE = '" & Trim(sPN) & "'"
'sSQL = sSQL & " AND RQDATE8_275 <'" & Format(Date, "yyyymmdd") & "'"
If sNG <> "" Then
sSQL = sSQL & " AND NETGRP_275 ='" & sNG & "'"
End If
Debug.Print sSQL
rst.Open sSQL, cnn, adOpenStatic, adLockReadOnly, adCmdText
[b]
On error resume next
[/b]
rst.MoveFirst
[b]
if err.number = 0 then
icol=1
for each fld in rst.fields
sheet2.cells(1,icol).value = fld.name
icol=icol+1
next
lrow = sheet2.[A1].currentregion.rows.count + 1
Sheet2.Cells(lrow,1).CopyFromRecordset rst
else
err.clear
msgbox "no rows"
end if
on error goto 0
[/b]
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing
End Function