I have a template WS and I delete any data so I update it. this code will not work directly because I have changed names so I don't get in trouble with work....
HTH...
and, of course, there are other ways to do the same thing....
Sub GetCF()
Dim OraDatabase As Object
Dim OraDynaSet As Object
Dim OraSession As Object
Dim qryStr As String
Dim Cntr As Integer, ThisMonth As Integer, x As Integer, LastRowCal As Integer, MonthNQtr As Integer, Mon2Add As Integer
Dim LastMonthQtr As Integer, y As Integer, test1 As Integer, LastDay As Integer
Dim JDate As Single, JDay As Single
Dim MyFY As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Application.DisplayStatusBar = True
Application.StatusBar = "Getting CF records from JDE. "
EndDate = InputBox("Enter Julian Date")
JDate = EndDate
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase = OraSession.OpenDatabase("JDPD", "username/password!", CInt(0)) ' JDPD is the name of our entry in the TNSNames.ora file - this gives the Socket info for the DB
' this is the SQL itself
qryStr = "select TRIM(mf.mflitm) Part_Number, "
qryStr = qryStr & "SUBSTR(TRIM(mf.mflitm), -3) MPF, "
qryStr = qryStr & "TRIM(im.imdsc1) Description, "
qryStr = qryStr & "TO_DATE(TO_CHAR(TO_NUMBER(SUBSTR(mf.mfdrqj,1,1))+ 19) || NVL(SUBSTR(mf.mfdrqj, 2, 5),'00001'),'YYYYDDD') Request_Date, "
qryStr = qryStr & "mf.mffqt Qty, "
qryStr = qryStr & "QC.cost QC "
qryStr = qryStr & "from proddta.f3460 mf, "
qryStr = qryStr & "proddta.f4101 im, "
qryStr = qryStr & "(SELECT (F4105.COUNCS / 10000) COST, "
qryStr = qryStr & "F4105.COLEDG LEDGER, "
qryStr = qryStr & "F4105.COMCU MCU, "
qryStr = qryStr & "F4105.COITM SHORT "
qryStr = qryStr & "FROM PRODDTA.tablename1,tablename2 "
qryStr = qryStr & "WHERE F4105.COLEDG IN ('QC') "
qryStr = qryStr & "AND F4105.COMCU = LPAD('000', 12)) QC "
qryStr = qryStr & "where mf.mfmcu = lpad('000',12) "
qryStr = qryStr & "and mf.mfitm = im.imitm "
qryStr = qryStr & "and mf.mfitm = qc.short "
qryStr = qryStr & "and mf.mfdrqj <= " & JDate
Set OraDynaSet = OraDatabase.DbCreateDynaset(qryStr, 0&)
Cntr = 2
Application.StatusBar = "Loading CF Data..."
Sheets(WSCF).Activate
Range("A2:F2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.ClearContents
If OraDynaSet.RecordCount >= 1 Then
With OraDynaSet
.MoveFirst
Do While Not .EOF
Cells(Cntr, 1).Value = OraDynaSet.Fields(0).Value
Cells(Cntr, 2).Value = OraDynaSet.Fields(1).Value
Cells(Cntr, 3).Value = OraDynaSet.Fields(2).Value
Cells(Cntr, 4).Value = OraDynaSet.Fields(3).Value
Cells(Cntr, 5).Value = OraDynaSet.Fields(4).Value
Cells(Cntr, 6).Value = OraDynaSet.Fields(5).Value
Cntr = Cntr + 1
.MoveNext
Loop
End With
Else
MsgBox "You Messed Up"
Exit Sub
End If
Cells(1, 1).Select
Set OraDynaSet = Nothing
Set OraSession = Nothing
Set OraDatabase = Nothing
Application.ScreenUpdating = True
Application.DisplayAlerts = True
Application.StatusBar = ""
End Sub
MODS: if this is getting to much like a real question that should be in a different area. I apologize and let me know....thanks....
Bookmarks