Toby1kenobe
Instructor
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("SELECT * FROM tblAssessments WHERE [Student Name] = '" & _
Forms![frmTabbedAssessmentSheet]![Student Name] & "' AND [Assessment Date] = #" & strAssessDate1 & "#"
If rstAssess1.EOF = False Then
'This record was successfully retreived - get the other one.
Set rstAssess2 = CurrentDb.OpenRecordset("SELECT * FROM tblAssessments WHERE [Student Name] = '" & _
Forms![frmTabbedAssessmentSheet]![Student Name] & "' AND [Assessment Date] = #" & strAssessDate2 & "#"
If rstAssess2.EOF = False Then
'This record was successfully retreived - work out the differences.
Set rstResult = CurrentDb.OpenRecordset("SELECT TOP 1 * FROM tblAssessmentsResults"
rstResult.Edit
rstResult("Student Name"
= 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 "Assessments", acPreview
DoCmd.Close acForm, "frmAssessmentDates"
Else
MsgBox "Second assessment record not found.", vbExclamation, Me.Caption
End If
Else
MsgBox "First assessment record not found.", vbExclamation, Me.Caption
End If
Else
MsgBox "The chosen dates must be different.", vbExclamation, Me.Caption
End If
Exit_preview_assessment_Click:
Exit Sub
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("SELECT * FROM tblAssessments WHERE [Student Name] = '" & _
Forms![frmTabbedAssessmentSheet]![Student Name] & "' AND [Assessment Date] = #" & strAssessDate1 & "#"
If rstAssess1.EOF = False Then
'This record was successfully retreived - get the other one.
Set rstAssess2 = CurrentDb.OpenRecordset("SELECT * FROM tblAssessments WHERE [Student Name] = '" & _
Forms![frmTabbedAssessmentSheet]![Student Name] & "' AND [Assessment Date] = #" & strAssessDate2 & "#"
If rstAssess2.EOF = False Then
'This record was successfully retreived - work out the differences.
Set rstResult = CurrentDb.OpenRecordset("SELECT TOP 1 * FROM tblAssessmentsResults"
rstResult.Edit
rstResult("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 "Assessments", acPreview
DoCmd.Close acForm, "frmAssessmentDates"
Else
MsgBox "Second assessment record not found.", vbExclamation, Me.Caption
End If
Else
MsgBox "First assessment record not found.", vbExclamation, Me.Caption
End If
Else
MsgBox "The chosen dates must be different.", vbExclamation, Me.Caption
End If
Exit_preview_assessment_Click:
Exit Sub