Hey! Thanks for all your help. I really appreciate it. However, I am still facing a problem. Now only part of the code works. It works until Recon is deleted. However, it says that object is required. I have just pasted my edited code below.
Private Sub Command22_Click()
On Error GoTo Command22_Click_Err
Dim dbsNorthwind As DAO.Database
Dim rstProducts As DAO.Recordset
Set dbsNorthwind = CurrentDb
Set rstProducts = dbsNorthwind.OpenRecordset("RMC(2G ONLY)_update")
'Declare Objects
Dim oExcel As Object
Dim obook As Object
Dim oSheet As Object
'Test for previous copy of file
If Dir("C:\100210\Recon.xls") <> "" Then
If Dir("C:\100210\ReconTemp.xls") <> "" Then
Kill "C:\100210\ReconTemp.xls"
End If
'Create a new blank formatted workbook
FileCopy "C:\100210\Recon.xls", "C:\100210\ReconTemp.xls"
Kill "C:\100210\Recon.xls"
End If
'Start a new workbook in Excel
Set oExcel = CreateObject("Excel.Application")
Set obook = oExcel.Workbooks.Open("C:\100210\ReconTemp.xls")
'Add data to cells of the first worksheet in the new workbook
Set oSheet = obook.Worksheets(1)
'There are various methods of populating the workbook
'Enter the method you prefer here
'The most common one would be to use the CopyFromRecordset command
'oSheet.Range("A2").Value = CopyFromRecordset rstProducts
oSheet.Range("A2").Value.CopyFromRecordset rstProducts
'Save the Workbook and Quit Excel
'You could give the workbook a generic name or hard code it yourself
obook.SaveAs "C:\100210\Recon.xls"
oExcel.Quit
'Destroy object references from cache
Set oExcel = Nothing
Set obook = Nothing
Set oSheet = Nothing
Command22_Click_Exit:
Exit Sub
Command22_Click_Err:
MsgBox Error$
Resume Command22_Click_Exit
End Sub
Thank you for ur help again. Hope u could help spot my mistake.
Thanks
