IMO
Now Known as ___
- Local time
- Today, 11:03
- Joined
- Sep 11, 2002
- Messages
- 723
I have a db which imports a sheet (Shipping Details) from Excel to a table. The user then selects a supplier code from a listbox for deletion and the following code runs a query (criteria based on the ListBox) to delete that supplier from the table, then transfers the table to a new sheet within the workbook, deletes the original sheet and renames the newly imported sheet. It then closes and saves the workbook without it being visible. This all works fine the first time it fires, but, if the user selects a second supplier for deletion, the code does not close and save the workbook.
Has anybody got an idea why this is? Any help greatly appreciated.
Thanks
IMO
Has anybody got an idea why this is? Any help greatly appreciated.
Thanks
IMO
Code:
Public Sub DeleteSheet()
DoCmd.OpenQuery "qryDeleteSupplier", acNormal, acEdit
DoCmd.TransferSpreadsheet acExport, 8, "Shipping Details", "H:\BIDataLoad\Supplier Orders.xls", True, ("Shipping_Details")
Dim objXL As Excel.Application
Dim objWkb As Excel.Workbook
Dim objSht As Excel.Worksheet
Dim db As Database
Const conWKB_NAME = "H:\BIDataLoad\Supplier Orders.xls"
Set db = CurrentDb
Set objXL = New Excel.Application
With objXL
.Visible = False
Set objWkb = .Workbooks.Open(conWKB_NAME)
.DisplayAlerts = False
Sheets("Shipping Details").Select
ActiveWindow.SelectedSheets.Delete
Sheets("Shipping_Details").Select
Sheets("Shipping_Details").name = "Shipping Details"
.DisplayAlerts = True
objXL.ActiveWorkbook.Save
objXL.ActiveWorkbook.Close
objXL.Quit
End With
Set objSht = Nothing
Set objWkb = Nothing
Set objXL = Nothing
Set db = Nothing
End Sub