473,378 Members | 1,218 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

transfer data from one table into another and then into excel sheet

40
Hi!
CAN I USE THE FOLLOWING CODE FOR TRANSFERING THE DATA FROM ONE TABLE INTO ANOTHER AND THEN INTO EXCEL SHEET BUT WHEN I RUN THE PROGRAME IT PRODUCES THE ERROR "OPERATION IS NOT ALLOWED WHEN THE OBJECT IS CLOSED " AND IT IS ON THE LINE
" fldcount = rs2.Fields.Count" IT IS NOT COUNTING THE FILED
THE VALUE IN fldcount =0 but IT SHOULD BE fldcount=2

please check the code and give some idea iam sending little bit of code

con.Open "Driver={SQL Server};Server=" & listserver & "; Database=stu;Uid=sa;Pwd=" & txtpassword & ";"

Str1 = "DROP TABLE New_Rec "
On Error GoTo Err
rs.Open Str1, con, adOpenDynamic, adLockBatchOptimistic, adCmdText

Str2 = "CREATE TABLE New_Rec (Rec_Id numeric, Rec_No integer)"
rs1.Open Str2, con, adOpenDynamic, adLockBatchOptimistic, adCmdText
squery = "INSERT INTO New_Rec SELECT * FROM OUTPUT"
rs2.Open squery, con, adOpenDynamic, adLockBatchOptimistic, adCmdText

Set xlApp = CreateObject("Excel.Application")
Set xlWb = xlApp.Workbooks.Open("c:\fin.xls")
Set xlWs = xlWb.Worksheets("sheet1")

xlApp.Visible = True ///// THE PROGRAME IS WORKING CORRECT UPTO THIS LINE
fldcount = rs2.Fields.Count ////// ERROR IS HERE
recarray = rs2.GetRows
reccount = UBound(recarray, 2) + 1
Mar 5 '08 #1
1 1805
QVeen72
1,445 Expert 1GB
Hi,

"Inserts/Updates/Deletes" should be executed on a Command Or Connection Object..
Split your Insert into 2 commands:

Expand|Select|Wrap|Line Numbers
  1. Str2 = "CREATE TABLE New_Rec (Rec_Id numeric, Rec_No integer)"
  2. Con.Execute str2
  3. squery = "INSERT INTO New_Rec SELECT * FROM OUTPUT"
  4. Con.Execute squery
  5.  
  6. squery = "Select * From New_Rec "
  7. rs2.Open squery, con, adOpenDynamic, adLockBatchOptimistic, adCmdText
  8. fldcount = rs2.Fields.Count   
  9. recarray = rs2.GetRows
  10. reccount = UBound(recarray, 2) + 1
  11.  
I guess, if you are using New_Rec as a Temporary Table, then no need to Drop it and Re-Create every time.. Just Deleteing Records from the table would suffice..

Regards
Veena
Mar 5 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Ksenia Marasanova | last post by:
Hi, I have a little problem with encoding. Was hoping maybe anyone can help me to solve it. There is some amount of data in a database (PG) that must be inserted into Excel sheet and emailed....
8
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though...
3
by: Mads Petersen | last post by:
I'm stuck in this code. Hope you can and will help me. I launch it from excel. I have made the following code work, but not as i whant. I need the ranges to be working with something like xlDown....
11
by: Hi5 | last post by:
Hi, I am new to access I usedto work in Oracle and Mysql. I am after a way that enables me to populate a database I designed in access with lots of data which can be sorted in excel sheets, ...
3
by: natrajsr | last post by:
Hi, I want to load the data of a excel sheet or in the exact excel sheet format into a Rich TextBox control. I have already worked with loading WORD into a Rich TextBox. It is working fine.;...
7
by: Vanessa | last post by:
hi Everyone, I have two questions on exporting data to Excel using ASP (w/o converting formatted excel file into web page and then plug in the dynamic data): 1. Can we export data into...
5
by: hmiller | last post by:
Hey there folks: I have been trying to get this work for about a week now. I'm new to VBA... I am trying to transfer a populated table in Access to an existing, but blank, Excel worksheet. I...
1
by: tamatem | last post by:
I have an excel sheet that contain colummns as in a table in a sql data base i want to transfer this data from the sheet to the table from business logic code layer not from the enterprise manager...
1
by: is49460 | last post by:
Good afternoon! I use transfer spreadsheet function the export data from one of the table into the excel spreat sheet. I use the following code: DoCmd.TransferSpreadsheet acExport, 8, "qry...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.