OK - so I had my boss - who I call Database Yoda - take a look and we decided that building a function that passes the info into an array and making a temptable would best pull what we need to build the crossover table.
I have an issue though - I am getting an OverFlow error on run. I changed AMax and Indx to Long because Amax feeds off the Record_No field which is defined as a Long Int and Indx feeds off AMax. But I still have an Overflow error. I thought perhaps it could be the size of the Array, but it mismatches when I set it to anything other than Integer. Here is the code:
Private Sub Command0_Click()
On Error GoTo Err_Command0_Click
' Set AMax to long because of Overflow error and since Indx is defined by AMax -
' it also becomes a long.
Dim RS As Object
Dim stSql, MyStaff As String
Dim con As Object
Dim MyYear, MyQtr As Integer
Dim Indx, AMax As Long
MyYear = DLookup("[Year]", "[Project Parameters]", "[Active] = True")
MyQtr = DLookup("[Quarter]", "[Project Parameters]", "[Active] = True")
AMax = DMax("[Record_No]", "[Activities]", True)
Dim MyArray(1000) As Integer
MyStaff = ""
For Indx = 1 To AMax
MyArray(Indx) = 0
Next Indx
DoCmd.SetWarnings False
DoCmd.RunSQL "DELETE TempExport.* FROM TempExport;"
DoCmd.SetWarnings True
Set con = Application.CurrentProject.Connection
stSql = "SELECT * FROM [Daily Time Study Log]"
stSql = stSql & " WHERE [Year] = " & MyYear & " AND [Quarter] = " & MyQtr
stSql = stSql & " ORDER BY [Staff ID#];"
Set RS = CreateObject("ADODB.Recordset")
RS.Open stSql, con, 1 ' 1 = adOpenKeyset
While (Not (RS.EOF))
If MyStaff <> RS(1) Then
If MyStaff <> "" Then
' DUMP ARRAY
For Indx = 1 To AMax
If MyArray(Indx) > 0 Then
My_SQL = "INSERT INTO [TempExport] ([Staff],[Index],[Units]) " + _
"SELECT '" & MyStaff & "', " & Str(Indx) & "," & Str(MyArray(Indx))
DoCmd.SetWarnings False
DoCmd.RunSQL My_SQL
DoCmd.SetWarnings True
End If
Next Indx
For Indx = 1 To AMax
MyArray(Indx) = 0
Next Indx
End If
MyStaff = RS(1)
End If
' PROCESS LINE
For Indx = 6 To 102
If Not IsNull(RS(Indx)) Then
MyArray(RS(Indx)) = MyArray(RS(Indx)) + 1
End If
Next Indx
RS.MoveNext
Wend
Exit_Command0_Click:
Exit Sub
Err_Command0_Click:
MsgBox Err.Description
Resume Exit_Command0_Click
End Sub