I've got a DB with information on problem resolution as it relates to computer workstations. I've got two tables - one with details on the problems for a given day and one summarizing all of the problems by type. I'm trying to code a loop to run through the data and add summary entries as needed. Here's the code:
<code>
Private Sub cmdExecute_Click()
Dim prstCasesTemp As ADODB.Recordset
Dim prstCasesSummary As ADODB.Recordset
Dim conn As ADODB.Connection
'create needed variables
Dim techno As Double
Dim emergencyno As Single
Dim hardwareno As Single
Dim softwareno As Single
Dim installno As Single
Dim otherno As Single
'create the recordsets
Set conn = CurrentProject.Connection
Set prstCasesTemp = New ADODB.Recordset
Set prstCasesSummary = New ADODB.Recordset
prstCasesTemp.Open "Cases Temp", conn, adOpenKeyset, adLockOptimistic
prstCasesSummary.Open "Cases Summary", conn, adOpenKeyset, adLockOptimistic
'begin the summary loop
prstCasesTemp.MoveFirst
Do While Not prstCasesTemp.EOF
techno = prstCasesTemp![swresolvedby]
'loop while the same tech is involved
Do While prstCasesTemp![swresolvedby] = techno
If prstCasesTemp![SWPRIORITY] = "1 - Emergency " Then
emergencyno = emergencyno + 1
Else
Select Case prstCasesTemp![swproblemarea]
Case "Hardware Fix "
hardwareno = hardwareno + 1
Case "Hardware/Drivers "
hardwareno = hardwareno + 1
Case "Software "
softwareno = softwareno + 1
Case "Install "
installno = installno + 1
Case Else
otherno = otherno + 1
End Select
End If
prstCasesTemp.MoveNext
Loop
'add an entry to the summary table
prstCasesSummary.AddNew
'add summarized data to the summary table
prstCasesSummary![DateClosed] = prstCasesTemp![swdateresolved]
prstCasesSummary![Technician] = techno
prstCasesSummary![Emergency] = emergencyno
prstCasesSummary![Hardware] = hardwareno
prstCasesSummary![Software] = softwareno
prstCasesSummary![Install] = installno
prstCasesSummary![Other] = otherno
prstCasesSummary.Update
emergencyno = 0
hardwareno = 0
softwareno = 0
installno = 0
otherno = 0
prstCasesTemp.MoveNext
Loop
prstCasesTemp.Close
prstCasesSummary.Close
End Sub
</code>
HERE'S THE PROBLEM:
When I try to add the summarized data to the summary table, I get an error that makes no sense to me (I'm guessing it's one of those 'forest for the trees' kind of thing). The error is as follows:
Run-time error '3265':
Item cannot be found in teh collection corresponding to the requested name or ordinal.
This error occurs on the lines for adding the summary data (from prstCasesTemp) to the summary table (prstCasesSummary).
Any suggestions? I've run loops similar to this before, but this one's giving me a headache.
<code>
Private Sub cmdExecute_Click()
Dim prstCasesTemp As ADODB.Recordset
Dim prstCasesSummary As ADODB.Recordset
Dim conn As ADODB.Connection
'create needed variables
Dim techno As Double
Dim emergencyno As Single
Dim hardwareno As Single
Dim softwareno As Single
Dim installno As Single
Dim otherno As Single
'create the recordsets
Set conn = CurrentProject.Connection
Set prstCasesTemp = New ADODB.Recordset
Set prstCasesSummary = New ADODB.Recordset
prstCasesTemp.Open "Cases Temp", conn, adOpenKeyset, adLockOptimistic
prstCasesSummary.Open "Cases Summary", conn, adOpenKeyset, adLockOptimistic
'begin the summary loop
prstCasesTemp.MoveFirst
Do While Not prstCasesTemp.EOF
techno = prstCasesTemp![swresolvedby]
'loop while the same tech is involved
Do While prstCasesTemp![swresolvedby] = techno
If prstCasesTemp![SWPRIORITY] = "1 - Emergency " Then
emergencyno = emergencyno + 1
Else
Select Case prstCasesTemp![swproblemarea]
Case "Hardware Fix "
hardwareno = hardwareno + 1
Case "Hardware/Drivers "
hardwareno = hardwareno + 1
Case "Software "
softwareno = softwareno + 1
Case "Install "
installno = installno + 1
Case Else
otherno = otherno + 1
End Select
End If
prstCasesTemp.MoveNext
Loop
'add an entry to the summary table
prstCasesSummary.AddNew
'add summarized data to the summary table
prstCasesSummary![DateClosed] = prstCasesTemp![swdateresolved]
prstCasesSummary![Technician] = techno
prstCasesSummary![Emergency] = emergencyno
prstCasesSummary![Hardware] = hardwareno
prstCasesSummary![Software] = softwareno
prstCasesSummary![Install] = installno
prstCasesSummary![Other] = otherno
prstCasesSummary.Update
emergencyno = 0
hardwareno = 0
softwareno = 0
installno = 0
otherno = 0
prstCasesTemp.MoveNext
Loop
prstCasesTemp.Close
prstCasesSummary.Close
End Sub
</code>
HERE'S THE PROBLEM:
When I try to add the summarized data to the summary table, I get an error that makes no sense to me (I'm guessing it's one of those 'forest for the trees' kind of thing). The error is as follows:
Run-time error '3265':
Item cannot be found in teh collection corresponding to the requested name or ordinal.
This error occurs on the lines for adding the summary data (from prstCasesTemp) to the summary table (prstCasesSummary).
Any suggestions? I've run loops similar to this before, but this one's giving me a headache.