Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Count number of Excel rows to be imported 1

Status
Not open for further replies.

RDS2

Technical User
Jun 6, 2003
44
US
Is there a way to count the number of rows that will be imported to an Access table using the Transfer Spreadsheet method?

I want to count the rows (in a selection) and display this in a message box so that I can cancel out of the routine if the row count is wrong.
 
You will get a trappable error if the sheet or range does not exist.

Code:
strSQL = "SELECT Count(*) As RecCount FROM [Sheet5$] " _
    & "IN '' [Excel 8.0;database=C:\Docs\LTD.xls;HDR=Yes];"
Set rs = CurrentDb.OpenRecordset(strSQL)

If Not rs.EOF Then
    MsgBox rs!RecCount & " found."
End If

Using a named range:

Code:
strSQL = "SELECT Count(*) As RecCount FROM Data_Range " _
    & "IN '' [Excel 8.0;database=C:\Docs\LTD.xls;HDR=Yes];"
Set rs = CurrentDb.OpenRecordset(strSQL)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top