Hi everyone,
First time poster, I've heard lots of great things! here's the problem I'm currently having, hopefully someone can provide assistance!
I have a folder containing MASTER databases for each month/year(MASTER0816, MASTER0916, etc) linked to one central Access database where I will be running my VBA coding.
Weekly I receive an excel sheet UDPATES that contains data that needs to be added to the MASTER databases. I take this data and separate it by month/year and make them their own spreadsheets (0816, 0916, 1016) and create a "Dates" excel sheet containing the unique month/years in the UPDATES sheet.
I am looking to import this data and then run an Unmatching + Append Query against the Master database. The problem is that the months that are being updated change every week and I want it to be dynamic as possible. I currently have it reading the Dates sheet and storing it in an array (which works perfectly). I don't know how to use this data to make the two necessary Dynamic Queries that will read the array (0816 for example) and know to use the table 0816 and MASTER0816 to run the unmatching/append queries before moving on to the next array.
Pseudo-Code: Read Dates sheet for unique months/years and store into array. Read first item in Array (0816) and run unmatching/append with MASTER0816 file. Go to next item in array.
Current Code: (This works fine but I don't know how to start with the queries, I'm a newbie when it comes to that sort of stuff).
EDIT: I forgot to mention this as I thought it was just a minor detail in the grand scheme of what I'm trying to do, but the Unmatching/Append queries would be based on the Unique ID: "Job ID"
First time poster, I've heard lots of great things! here's the problem I'm currently having, hopefully someone can provide assistance!
I have a folder containing MASTER databases for each month/year(MASTER0816, MASTER0916, etc) linked to one central Access database where I will be running my VBA coding.
Weekly I receive an excel sheet UDPATES that contains data that needs to be added to the MASTER databases. I take this data and separate it by month/year and make them their own spreadsheets (0816, 0916, 1016) and create a "Dates" excel sheet containing the unique month/years in the UPDATES sheet.
I am looking to import this data and then run an Unmatching + Append Query against the Master database. The problem is that the months that are being updated change every week and I want it to be dynamic as possible. I currently have it reading the Dates sheet and storing it in an array (which works perfectly). I don't know how to use this data to make the two necessary Dynamic Queries that will read the array (0816 for example) and know to use the table 0816 and MASTER0816 to run the unmatching/append queries before moving on to the next array.
Pseudo-Code: Read Dates sheet for unique months/years and store into array. Read first item in Array (0816) and run unmatching/append with MASTER0816 file. Go to next item in array.
Current Code: (This works fine but I don't know how to start with the queries, I'm a newbie when it comes to that sort of stuff).
Code:
Public Sub ImportExcels()
Dim xl As Excel.Application, xlsht As Excel.Worksheet, xlWrkBk As Excel.Workbook, rng As Excel.Range, cell As Excel.Range
Dim RowCount As Long, TheMonths() As String, i As Integer, SQLUnmatching As String, SQLAppend As String
Dim FilePath As String, DatesLoc As String, ImportPath As String
FilePath = "H:\"
ImportPath = FilePath & Format(Date, "mm") & "." & Format(Date, "dd") & "." & Format(Date, "yy") & "\"
Set xl = CreateObject("Excel.Application")
Set xlWrkBk = xl.Workbooks.Open(ImportPath & "Dates.xlsx")
Set xlsht = xlWrkBk.Worksheets(1)
RowCount = xlsht.Cells(Rows.Count, "A").End(xlUp).Row
Set rng = xlsht.Range("A2:A" & RowCount)
ReDim TheMonths(1 To rng.Rows.Count)
i = 1
For Each cell In rng
TheMonths(i) = cell.Value
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, TheMonths(i), ImportPath & TheMonths(i) & ".xlsx", True
i = i + 1
Next cell
xlWrkBk.Close False
xl.Quit
Set xlsht = Nothing
Set xlWrkBk = Nothing
Set xl = Nothing
End Sub
EDIT: I forgot to mention this as I thought it was just a minor detail in the grand scheme of what I'm trying to do, but the Unmatching/Append queries would be based on the Unique ID: "Job ID"
Last edited: