|
-
Jul 14th, 2003, 04:03 AM
#1
Thread Starter
Addicted Member
sql results in excel
The following code shows that if I run the micro command in the first sheet (sheet1) of my workbook then the results of the query they will be presented in sheet1.
What changes should I make in the code in order to are presented the results in an other sheet e.g. Sheet2.
Sub Refresh()
'Declare variables
Dim OraSession As Object
Dim OraDatabase As Object
Dim EmpDynaset As Object
Dim flds() As Object
Dim fldcount As Integer
Dim userentry As String
Dim dtentryFROM As Date
Dim dtentryTO As Date
Dim strdtfrom As String
Dim strdtto As String
'dtentryTO = Format(dd / mm / yyyy)
strdtfrom = InputBox("From Date:")
strdtto = InputBox("To Date:")
userentry = InputBox("Please give User")
Set OraSession = CreateObject("OracleInProcServer.XOraSession")
Set OraDatabase = OraSession.OpenDatabase("mydb", "username/pass", 0&)
Set EmpDynaset = OraDatabase.CreateDynaset("SELECT ROWNUM, tbl1, tbl2 FROM data WHERE date>= TO_DATE ('" + strdtfrom + "', 'DD/MM/RRRR') AND date< TO_DATE ('" + strdtto + "', 'DD/MM/RRRR') AND user = " + userentry + " ORDER BY date, ROWNUM", 0&)
'Set objSht = objWkb.Worksheets(class)
'Worksheets(class).
Range("A2:C2000").Select
'Range("A2:C2000").Select
Selection.ClearContents
'Declare and create an object for each column.
'This will reduce objects references and speed
'up your application.
fldcount = EmpDynaset.Fields.Count
ReDim flds(0 To fldcount - 1)
For colnum = 0 To fldcount - 1
Set flds(colnum) = EmpDynaset.Fields(colnum)
Next
'Insert Column Headings
'For Colnum = 0 To EmpDynaset.Fields.Count - 1
'ActiveSheet.Cells(1, Colnum + 1) = flds(Colnum).Name
'Next
'Display Data
For Rownum = 2 To EmpDynaset.RecordCount + 1
For colnum = 0 To fldcount - 1
ActiveSheet.Cells(Rownum, colnum + 1) = flds(colnum).Value
Next
EmpDynaset.MoveNext
Next
Range("A2:A2").Select
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|