RANDALL R ANTHONY
RRANTHON at sentara.com
Mon Sep 3 11:30:28 CDT 2007
Greetings all, I'm trying to do something fairly simple here, export a table to an excel spreadsheet. Tried one method, didn't work. Copied Dev's export function below. It works perfectly fine until the CopyFromRecordset hits the fourth record, and gives me an 'Automation Error, Method 'CopyFromRecordset' of object 'Range' failed.' Any ideas? M$'s KB and googling have been fruitless. Thanks! 'copyright - dev ashish Dim objXL As Excel.Application Dim objWkb As Workbook Dim objSht As Worksheet Set rs = CurrentDb.OpenRecordset(sSQL, _ dbOpenSnapshot) iMaxCol = rs.Fields.Count If rs.RecordCount > 0 Then rs.MoveLast: rs.MoveFirst iMaxRow = rs.RecordCount Set objXL = New Excel.Application With objXL .Visible = True Set objWkb = .Workbooks.ADD Set objSht = objWkb.Worksheets(1) With objSht .Cells.Columns.AutoFit .Range(.Cells(1, 1), .Cells(iMaxRow, _ iMaxCol)).CopyFromRecordset rs End With End With End If