Code:
Option Compare Database
Function ImpoThisYears_allExcel()
'Imports all of this years data to date. From excel it also inserts date and shift stamps for each excel file for tracking deletes any empty rows.
'Set Variables
Dim ShiftStrg As String
Dim MyFolderPath As String
Dim MyPath As String
Dim MyTableName As String
Dim DateStrg As String
Dim strSQL As String
Dim strDeleteSQL As String
Dim MyFileName As String
Dim DateStrgFormatted As String
Dim ThisYear As Date
Dim TodaysDt As Date
Dim EndJ As String
Dim J As String
J = 0
ThisYear = "01/01/2014"
TodaysDt = Date
'Debug.Print (ThisYear)
'Debug.Print (TodaysDt)
EndJ = TodaysDt - ThisYear
'Debug.Print (EndJ)
'Step Trough all date so far this year
Do While J < EndJ
For k = 1 To EndJ
J = k
'Debug.Print (k)
'Debug.Print (J)
DateStrg = Date - k
DateStrgFormatted = Format(DateStrg, "YYYY-MM-DD ")
' Debug.Print (DateStrgFormatted)
'Below steps to change from day shift to night shift on each DAY change.
For i = 1 To 2
'Debug.Print (i)
If i = 1 Then
ShiftStrg = "Day"
Else
ShiftStrg = "Night"
End If
MyFileName = DateStrgFormatted & ShiftStrg & " Shift.xlsx"
MyFolderPath = "X:\Gordonsville\Mine ops\Daily Forman Paper Work\CUMB Leadmen Paperwork\Daily Shift Reports 2013\"
MyPath = MyFolderPath & MyFileName
'Debug.Print (MyPath)
MyTableName = "2014 Cumberland Daily Shift Reports"
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, MyTableName, MyPath, False, "A6:Q30"
'Insert Date( F1) and Shift (F16) for each sheet
strSQL = "Update [2014 Cumberland Daily Shift Reports] SET F1='" & DateStrg & "',F16='" & ShiftStrg & "' WHERE F2 is not null AND F1 is null"
'Debug.Print (strSQL)
CurrentDb.Execute strSQL
Next
Next
Loop
strDeleteSQL = "DELETE [2014 Cumberland Daily Shift Reports].F2, [2014 Cumberland Daily Shift Reports].F3, [2014 Cumberland Daily Shift Reports].F5 FROM [2014 Cumberland Daily Shift Reports] WHERE [2014 Cumberland Daily Shift Reports].F2 Is Null AND [2014 Cumberland Daily Shift Reports].F3 Is Null AND [2014 Cumberland Daily Shift Reports].F5 Is Null"
CurrentDb.Execute strDeleteSQL
End Function
got it to do everything I wanted. Probably went about it the long way, just did it the way I would a matlab program lol. I have several locations that with data that is saved this way. So now all I need to do is change a few things to get it to work.
Thanks for help guys.