Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default 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.(i got an error msg on
line"Range("sheet2!A1:C1000").Select")
What changes should I make in the code in order to are presented the
results in an other sheet e.g. Sheet2.

Private Sub OKclass_Click()
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
Dim XL Application
Dim Wkb As Workbook
Dim ws As Worksheet
Set ws = ActiveWorkbook.Sheets("class")
'dtentryTO = Format(dd / mm / yyyy)
strdtfrom = InputBox("From Date:")
strdtto = InputBox("To Date:")
userentry = InputBox("Please give User_Id")

Set OraSession = CreateObject("OracleInProcServer.XOraSession")

Set OraDatabase = OraSession.OpenDatabase("mydb", "username/pass", 0&)

Set EmpDynaset = OraDatabase.CreateDynaset("SELECT ROWNUM,tbl1,tbl2
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&)

Range("sheet2!A1:C1000").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
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Conditional Sum Argument results do not equal cell results Excel Randy R Mullins Excel Worksheet Functions 3 August 9th 06 07:16 PM
Excel results template janr Excel Discussion (Misc queries) 1 June 13th 06 03:11 PM
Voting results in Excel Arnaki Excel Discussion (Misc queries) 0 May 3rd 06 06:34 AM
When running a SAP report Excel will only display results if Excel isn't already open peternoy Excel Discussion (Misc queries) 0 January 19th 06 11:03 AM
sql results in excel andyL Excel Programming 2 July 15th 03 07:21 AM


All times are GMT +1. The time now is 10:23 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"