Hello,
I am having some trouble getting a table to open up as an Excel file after you press a button on a form. So far I have part of the code working where it will open up the Excel file but it will only display the headers and no information. I know which line of the code is not working just not sure why.
Any help with this would be appreciated.
Thanks,
Slen
Here is what I have so far
I am having some trouble getting a table to open up as an Excel file after you press a button on a form. So far I have part of the code working where it will open up the Excel file but it will only display the headers and no information. I know which line of the code is not working just not sure why.
Any help with this would be appreciated.
Thanks,
Slen
Here is what I have so far
Code:
Dim db As DAO.Database
Dim rs As DAO.Recordset
Set db = CurrentDb
Set rs = db.OpenRecordset("tbl adj and refunds", dbOpenSnapshot)
'Start a new workbook in Excel
Dim oApp As New Excel.Application
Dim oBook As Excel.Workbook
Dim oSheet As Excel.Worksheet
Set oBook = oApp.Workbooks.Add
Set oSheet = oBook.Worksheets("Sheet1")
oApp.Visible = True
oApp.UserControl = True
fldCount = rs.Fields.Count
For iCol = 1 To fldCount
oSheet.Cells(1, iCol).Value = rs.Fields(iCol - 1).Name
Next
'**[B]The line below is the problem, nothing copies[/B]**
oSheet.Range("A2").CopyFromRecordset rs
'Format the header row as bold and autofit the columns
With oSheet.Range("A1").Resize(1, fldCount)
.Font.Bold = True
.EntireColumn.AutoFit
End With
'Close the Database and Recordset
rs.Close
db.Close
Comment