Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"No Current Record" Any Ideas????

Status
Not open for further replies.

Toby1kenobe

Instructor
May 26, 2002
66
GB
I have this chunk of code to compare two sets of data, which almost works. When it runs it can find the data it requires but then gives the error message "No Current Record". Can Anybody see whats wrong?

Thanks in advance, heres the code

Private Sub cmdView_Click()
Dim strAssessDate1 As String, strAssessDate2 As String
Dim rstAssess1 As DAO.Recordset, rstAssess2 As DAO.Recordset, rstResult As DAO.Recordset

On Error GoTo Err_preview_assessment_Click

'check that the same date has not been chosen in both fields.
If Me.Date1 <> Me.Date2 Then

'Ask user for two assessment dates.
strAssessDate1 = SQLDate(Me.Date1)
strAssessDate2 = SQLDate(Me.Date2)

'Retreive these assessment records.
Set rstAssess1 = CurrentDb.OpenRecordset(&quot;SELECT * FROM tblAssessments WHERE [Student Name] = '&quot; & _
Forms![frmTabbedAssessmentSheet]![Student Name] & &quot;' AND [Assessment Date] = #&quot; & strAssessDate1 & &quot;#&quot;)
If rstAssess1.EOF = False Then
'This record was successfully retreived - get the other one.
Set rstAssess2 = CurrentDb.OpenRecordset(&quot;SELECT * FROM tblAssessments WHERE [Student Name] = '&quot; & _
Forms![frmTabbedAssessmentSheet]![Student Name] & &quot;' AND [Assessment Date] = #&quot; & strAssessDate2 & &quot;#&quot;)
If rstAssess2.EOF = False Then
'This record was successfully retreived - work out the differences.
Set rstResult = CurrentDb.OpenRecordset(&quot;SELECT TOP 1 * FROM tblAssessmentsResults&quot;)

rstResult.Edit
rstResult(&quot;Student Name&quot;) = Forms![frmTabbedAssessmentSheet]![Student Name]
'summarise relevant fields.
For i = 6 To 35
Debug.Print rstAssess2.Fields(i).Name
rstResult.Fields(i) = CInt(rstAssess2.Fields(i)) - CInt(rstAssess1.Fields(i))
Next i
rstResult.Update

'Now view the report.
DoCmd.OpenReport &quot;Assessments&quot;, acPreview

DoCmd.Close acForm, &quot;frmAssessmentDates&quot;
Else
MsgBox &quot;Second assessment record not found.&quot;, vbExclamation, Me.Caption
End If
Else
MsgBox &quot;First assessment record not found.&quot;, vbExclamation, Me.Caption
End If
Else
MsgBox &quot;The chosen dates must be different.&quot;, vbExclamation, Me.Caption
End If

Exit_preview_assessment_Click:
Exit Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top