Dim db As DAO.Database
Set db = CurrentDb
Dim rst As DAO.Recordset
Dim MyForm As Form
Set MyForm = Forms!QC_Query_form
For Each ctl In MyForm.Controls
Select Case ctl.ControlType
Case acCheckBox
If ctl = True Then
Set rst = db.OpenRecordset(ctl.Name)
If Not rst.EOF Then
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel9, ctl.Name, fileIn, True, ""
End If
rst.Close
Set rst = Nothing
End If
End Select
Next ctl
Set xlApp = CreateObject("Excel.Application")
Set xlBook = xlApp.Workbooks.Open(fileIn) [B][COLOR=red]'this is where its trying to open the spreadsheet but since no results in the case loop there is no spredsheet and so the error is generate saying cant find the file[/COLOR][/B]
Dim intCountofSheets, intCurrentSheet As Integer
intCountofSheets = xlBook.Sheets.Count
intCurrentSheet = 1
Do While intCurrentSheet <= intCountofSheets
xlBook.Worksheets(intCurrentSheet).Activate
With xlApp.ActiveSheet
.Columns.Select