samonwalkabout
Registered User.
- Local time
- Today, 20:33
- Joined
- Mar 14, 2003
- Messages
- 185
From a form i have a command button that gives an excel out put of a 3 querys onto 3 tabs of an excel file. It then opens the file and formats the data slightly. This works fine. Once then if i try the same thing again it give an error. If i close the db re-open and try again it works but only the frist time. Error is
"Object variable or With Block not set"
Code is
DoCmd.OutputTo acOutputQuery, stDocName, acFormatXLS, "c:\BudgetExcelLO.xls" ' create sheet
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "qryeeLO", "c:\BudgetExcelLO.xls", , "AllRawMaterials" 'export1
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "qryEESolLO", "c:\BudgetExcelLO.xls", , "JustSolvents" ' export2
MsgBox "The Excel Sheet BudgetExcelLO has been created on the C Drive of this computer" 'tell user
Call OpenExcel("c:\BudgetExcelLO.xls") ' open sheet
ActiveWindow.TabRatio = 0.503
Sheets("AllRawMaterials").Select
Range("F2").Select
ActiveCell.FormulaR1C1 = "=LOOKUP(RC[-1],qryrates!R2C[-5]:R5C[-4])"
Range("F2").Select
Selection.AutoFill Destination:=Range("F2:F53")
Range("F2:F53").Select
Range("G2").Select
ActiveCell.FormulaR1C1 = "=(RC[-3]*RC[-1])"
etc etc etc etc etc etc etc
Code complies fine and only gives error the 2nd time i run it.
Any ideas?
"Object variable or With Block not set"
Code is
DoCmd.OutputTo acOutputQuery, stDocName, acFormatXLS, "c:\BudgetExcelLO.xls" ' create sheet
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "qryeeLO", "c:\BudgetExcelLO.xls", , "AllRawMaterials" 'export1
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel97, "qryEESolLO", "c:\BudgetExcelLO.xls", , "JustSolvents" ' export2
MsgBox "The Excel Sheet BudgetExcelLO has been created on the C Drive of this computer" 'tell user
Call OpenExcel("c:\BudgetExcelLO.xls") ' open sheet
ActiveWindow.TabRatio = 0.503
Sheets("AllRawMaterials").Select
Range("F2").Select
ActiveCell.FormulaR1C1 = "=LOOKUP(RC[-1],qryrates!R2C[-5]:R5C[-4])"
Range("F2").Select
Selection.AutoFill Destination:=Range("F2:F53")
Range("F2:F53").Select
Range("G2").Select
ActiveCell.FormulaR1C1 = "=(RC[-3]*RC[-1])"
etc etc etc etc etc etc etc
Code complies fine and only gives error the 2nd time i run it.
Any ideas?