Hello,
I have been reading the tek-tips on this issue but I still can't seem to get the matter resolved. I am importing multiple excel files into access. The importing works with no problem the first time, but I have excel.exe running in the task manager. When I import a second time the task manager shows a second Excel.exe during the execution. I used the END code and it removes the second Excel.exe with no problem but the first Excel.exe is still there and I get a message box that pops up saying "File Now Available"
"(filename) is now available for editing choose Read-Write to open it for editing."
If anyone has any ideas to stop this i would greatly appreciate it.
I have been reading the tek-tips on this issue but I still can't seem to get the matter resolved. I am importing multiple excel files into access. The importing works with no problem the first time, but I have excel.exe running in the task manager. When I import a second time the task manager shows a second Excel.exe during the execution. I used the END code and it removes the second Excel.exe with no problem but the first Excel.exe is still there and I get a message box that pops up saying "File Now Available"
"(filename) is now available for editing choose Read-Write to open it for editing."
If anyone has any ideas to stop this i would greatly appreciate it.
Code:
Private Sub btnImportData_Click()
Dim GetFile
Dim sql_Del As String
Dim sql_Upd As String
Dim VAR_SLASH As Integer
Dim VAR_SLASH_FNL As Integer
Dim CHAR_SLASH As String
Dim FILE_STR As String
Dim xl As Excel.Application
Set xl = New Excel.Application
GetFile = xl.GetOpenFilename("Excel Files (*.xls), *.xls", , "Select Site Excel file", , True)
On Error GoTo Err_btnImportData_Click:
For Each item1 In GetFile
For VAR_SLASH = 1 To 500
CHAR_SLASH = Left(Right(item1, VAR_SLASH), 1)
If CHAR_SLASH = "\" Then
VAR_SLASH_FNL = VAR_SLASH
Exit For
Else
End If
Next VAR_SLASH
FILE_STR = Right(item1, VAR_SLASH_FNL - 1)
xl.Workbooks.Open item1
DoCmd.SetWarnings False
xl.ActiveWorkbook.Unprotect PassWord:="password"
xl.ActiveSheet.Unprotect PassWord:="password"
xl.Cells.Select
xl.Range("J1").Activate
xl.Selection.EntireColumn.Hidden = False
DoCmd.TransferSpreadsheet acImport, , "tbl_ImportData_Temp", item1, True, "A:I"
sql_Upd = "UPDATE tbl_ImportData_Temp LEFT JOIN tbl_ImportData ON (tbl_ImportData_Temp.DateNominated ="
sql_Upd = sql_Upd & " tbl_ImportData.DateNominated) AND (tbl_ImportData_Temp.AwardType = tbl_ImportData.AwardType)"
sql_Upd = sql_Upd & " AND (tbl_ImportData_Temp.Site = tbl_ImportData.Site) AND (tbl_ImportData_Temp.EmpID ="
sql_Upd = sql_Upd & " tbl_ImportData.EmpID) SET tbl_ImportData.EmpID = tbl_ImportData_Temp.EmpID, tbl_ImportData.LastName"
sql_Upd = sql_Upd & " = tbl_ImportData_Temp.LastName, tbl_ImportData.FirstName = tbl_ImportData_Temp.FirstName,"
sql_Upd = sql_Upd & " tbl_ImportData.MI = tbl_ImportData_Temp.MI, tbl_ImportData.Site = tbl_ImportData_Temp.Site,"
sql_Upd = sql_Upd & " tbl_ImportData.AwardType = tbl_ImportData_Temp.AwardType, tbl_ImportData.Amount ="
sql_Upd = sql_Upd & " tbl_ImportData_Temp.Amount, tbl_ImportData.Notes = tbl_ImportData_Temp.Notes,"
sql_Upd = sql_Upd & " tbl_ImportData.DateNominated = tbl_ImportData_Temp.DateNominated;"
sql_Del = "DELETE tbl_ImportData_Temp.* FROM tbl_ImportData_Temp;"
DoCmd.RunSQL sql_Upd
DoCmd.RunSQL sql_Del
xl.Workbooks(FILE_STR).Close savechanges:=False
xl.Quit
Next
Set xl = Nothing
Set xlApp = Nothing
Set xlBook = Nothing
Set xlSheet = Nothing
MsgBox "Done Importing!"
End
Err_btnImportData_Click:
Exit Sub
End Sub