Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reg: Incorrect RecordCount when opened a Excel sheet in ADO Recordset

Hi All,

I use ADO to open a Excel file using Jet OLEDB Provider.
I have one issue in getting the recordcount.

I open a excel sheet in ADO recordset

I have a Excel that can contain many sheets. I open a excel sheet
using ADO recordset, like

rst.Open ("select * from [Sheet1$]", conn);

Assume , The excel sheet "Sheet1" contain only Column headers and no
data rows.
If I open the excel sheet, the recordset rst shows a recordcount 0
(it actually showed recordcount as 30) and the EOF property is also
false.

Any idea ?

Thanks in advance
Dev

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Incorrect RecordCount when opened a Excel sheet in ADO Recordset

You probably need to go into the sheet and manually delete all the rows
below the header row (entire rows, not cells). then save the workbook. If
you then do Edit=goto special and select last cell, it will take you to the
last filled cell on the header row (if not, you didn't do it right). Then
you should get the proper count I would think.

--
Regards,
Tom Ogilvy

"dev" wrote in message
ups.com...
Hi All,

I use ADO to open a Excel file using Jet OLEDB Provider.
I have one issue in getting the recordcount.

I open a excel sheet in ADO recordset

I have a Excel that can contain many sheets. I open a excel sheet
using ADO recordset, like

rst.Open ("select * from [Sheet1$]", conn);

Assume , The excel sheet "Sheet1" contain only Column headers and no
data rows.
If I open the excel sheet, the recordset rst shows a recordcount 0
(it actually showed recordcount as 30) and the EOF property is also
false.

Any idea ?

Thanks in advance
Dev



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,253
Default Reg: Incorrect RecordCount when opened a Excel sheet in ADO Recordset



first check the usedrange in the excel sheet.
(ctrl End)
if you have cells containing spaces or formatting
then what appears to be empty is not.


then check:
connect string
clientside cursor


Sub getRecords()
Dim oCon As ADODB.Connection
Dim oRst As ADODB.Recordset

Set oCon = New ADODB.Connection

oCon.CursorLocation = adUseClient
oCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Extended Properties='Excel 8.0;Header=Yes';" & _
"Data Source=c:\headersonly.xls"

Set oRst = oCon.Execute("Select * from [Sheet1$]")
MsgBox "Should be 0 records:" & vbLf & oRst.RecordCount
oRst.Close
oCon.Close

End Sub

note that since no records were retrieved
both BOF and EOF are true


--
keepITcool
| www.XLsupport.com | keepITcool chello nl | amsterdam


dev wrote :

Hi All,

I use ADO to open a Excel file using Jet OLEDB Provider.
I have one issue in getting the recordcount.

I open a excel sheet in ADO recordset

I have a Excel that can contain many sheets. I open a excel sheet
using ADO recordset, like

rst.Open ("select * from [Sheet1$]", conn);

Assume , The excel sheet "Sheet1" contain only Column headers and no
data rows.
If I open the excel sheet, the recordset rst shows a recordcount 0
(it actually showed recordcount as 30) and the EOF property is also
false.

Any idea ?

Thanks in advance
Dev

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Reg: Incorrect RecordCount when opened a Excel sheet in ADO Recordset



Hi,

Thanks.

The control went to the 30th row. Now I deleted the row correctly and
the problem is solved (I have deleted the data in cells and not the
actual row).

But I have another question..
This excel sheet will be given by the end user and my system loads it
and scans for the record..no manual opening in between this process. If
the user had made the same mistake that I did...( not deleting the rows)
then is there any way to handle the problem.?

Also,
there might be some possibilities that the excel sheet to contain blank
rows inbetween the data records. I need to find that and remove all
those..

I am using ASP to open the excel file and reading it.

I would like to do all this using ADO?

Thanks

devi



*** Sent via Developersdex http://www.developersdex.com ***
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 233
Default Reg: Incorrect RecordCount when opened a Excel sheet in ADO Recordset

I suspect this is not possible in ADO (it is possible in Excel).

A suggestion is:
Loop through all records and check a column for being empty. You could
try to delete them. I'm not sure that will work however, since ADO with
EXCEL has some limitations.

In excel you can do all kind of tricks:

On closing the workbook you could delete all blank rows in the
usedrange

Sub Workbook_close

Thisworkbook.Sheets("Mysheet).UsedRange.Columns(1) .SpecialCells(xlCellTypeBlanks).EntireRow.Delete

end sub

this will delete all rows that are empty in column 1 of your sheet.


DM Unseen



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
Incorrect row number in my excel spread sheet hsvgal Excel Discussion (Misc queries) 1 July 30th 08 02:18 AM
Can I set up Excel sheet that auto increments a no. when opened Craneman Excel Discussion (Misc queries) 2 May 1st 08 09:53 AM
ADO - recordset - closed excel workbook - know sheet name and cell name but no named ranges defined grahamd Excel Programming 1 October 18th 04 06:13 PM
Recordset.Recordcount Returns -1! Sauron[_24_] Excel Programming 1 June 28th 04 09:11 AM
RecordCount problem Terence Excel Programming 1 August 11th 03 09:10 AM


All times are GMT +1. The time now is 09:08 AM.

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

About Us

"It's about Microsoft Excel"