Private Sub MassImport_DblClick(Cancel As Integer)
'import query code
importSQL = "INSERT INTO FORECAST ( YYYYMM, [Year], District, ProductLine, Type, Account, OCT, NOV, [DEC], QTR1, JAN, FEB, MAR, QTR2, APR, MAY, JUN, QTR3, JUL, AUG, SEP, QTR4, FYTOTAL, ImportTime ) " _
& "SELECT DATA.YYYYMM, DATA.Year, DATA.District, DATA.ProductLine, DATA.Type, DATA.Account, DATA.OCT, DATA.NOV, DATA.DEC, DATA.QTR1, DATA.JAN, DATA.FEB, DATA.MAR, DATA.QTR2, DATA.APR, DATA.MAY, DATA.JUN, DATA.QTR3, DATA.JUL, DATA.AUG, DATA.SEP, DATA.QTR4, DATA.FYTOTAL, DATA.LastSave " _
& "FROM DATA;"
' if combo box for path Null, go back and select path in
If IsNull(Me!ComboPaths) Then
MsgBox "Please Select the folder path in the Drop Down Box", vbCritical, "ComboBox Error"
DoCmd.GoToControl "ComboPaths"
Exit Sub
Else
End If
On Error Resume Next
DoCmd.DeleteObject acTable, "DATA"
Dim cnnLocal As New ADODB.Connection
Dim rstCurr As New ADODB.Recordset
Set cnnLocal = CurrentProject.Connection
'Get file name from Control Table
rstCurr.Open "SELECT CONTROL.ImportFileName FROM Control WHERE (((CONTROL.Visible)=Yes) AND ((CONTROL.Imported)=No)); ", cnnLocal, adOpenStatic, adLockPessimistic
With rstCurr
Do Until .EOF
For Each fldCurr In .Fields
'Concatenate Path from combobox with filename from Control table
anyFileName = fldCurr.Value
anyPath = Forms!MassImport.[ComboPaths] & "\" & anyFileName & ".xls"
Debug.Print anyPath
On Error GoTo SecondTry
DoCmd.SetWarnings False
If Dir(anyPath) <> "" Then
DoCmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel9, "DATA", anyPath, True, "ACCESSPASTE"
DoCmd.RunSQL importSQL
DoCmd.DeleteObject acTable, "DATA"
GoTo Done
Else
End If
Next
.MoveNext
Loop
End With
rstCurr.Close
Set cnnLocal = Nothing
Set rstCurr = Nothing
MsgBox "Available Files Imported Successfully", vbOKOnly,
importedSQL = "UPDATE FORECAST INNER JOIN (CONTROL INNER JOIN DISTRICTS ON CONTROL.HyperionDistrict = DISTRICTS.HyperionDistrict) ON FORECAST.District = DISTRICTS.District " _
& "SET CONTROL.Imported = Yes WHERE (((FORECAST.Locked)=No)); "
DoCmd.SetWarnings False
DoCmd.RunSQL importedSQL
DoCmd.SetWarnings True
Exit_MassImport_DblClick:
DoCmd.SetWarnings True
Exit Sub
Err_MassImport_DblClick:
MsgBox Err.Description
GoTo Done
End Sub