Basically, you've created an array of the tasks and task frequency for each supervisor. While I agree with Sal that the best way to resolve your challenge would be to restructure your tables to normalize your data, sometimes that is much easier said than done. I have a situation similar to yours where I receive source files from several operating locations that I must import to a centralized database. Some of the file come nice and neat with one row of data for each person for each day hours were billed. And I have a few that send files with one row per person and columns for each date containing the number of hours billed on that date.
I built a procedure that first determines what file type is being imported, list type or array, by reviewing the column headings. If the procedure cycles through all the columns without finding a date for a column heading, then I know I have a list type table and call a procedure to import the data from the list. Likewise, if the procedure encounters a column header that is a date, I know I have an array type table and call a different procedure to import the data from the array.
The following is the procedure that imports the data from the array to my normalized data table.
I've made the changes to my code to match your scenario. However, this has not been tested!
Code:
Sub TaskFreq_Array()
Dim db As DAO.Database
Dim rsTbl1 As DAO.Recordset, rsTbl2 As DAO.Recordset
Dim strBldg As String, strSupv As String, strFloor As String
Dim strPrevSupv As String, strArea As String
Dim strTaskFreq as String, strTask as String
Dim blnSameSupv As Boolean
Dim intTask As Integer
Dim fld As Field
DoCmd.Hourglass True
Set db = CurrentDb()
Set rsTbl1 = db.OpenRecordset("Table1", dbOpenDynaset)
Set rsTbl2 = db.OpenRecordset("Table2", dbOpenDynaset)
rsTbl1.MoveFirst
Do until rsTbl1.EOF
For Each fld In rsTbl1.Fields
Select Case fld.Name
Case "Building"
strBldg = fld.Value
Case "Supervisor"
strSupv = fld.Value
Case "Floor"
strFloor = fld.Value
Case "Area"
strArea = fld.Value
Case Else
intTask = fld.CollectionIndex
If (intTask Mod 2) = 0 Then
strTaskFreq = rsTbl1.Fields(intTask)
Else
strTask = rsTbl1.Fields(intTask)
With rsTbl2
.AddNew
!Building = strBldg
!Supervisor = strSupv
!Floor = strFloor
!Area = strArea
!Task_Frequency = strTaskFreq
!Task = strTask
.update
End With
End If
End Select
Next fld
rsTbl1.MoveNext
Loop
rsTbl1.Close
rsTbl2.Close
Set rsTbl1 = Nothing
Set rsTbl2 = Nothing
Set db = Nothing
DoCmd.Hourglass False
End Sub
I hope this helps.
Darrell L. Embrey