Private Sub Report_Open(Cancel As Integer)
On Error GoTo Err_Handler
'set information for error log
strItemName = Me.Name
SetNewObjectLogItems
'CR v4633W - modified code to update column width dynamically depending on number of subjects
AllSubjectGridWidth = 19.95 'width of all columns used for subject grades
'Get list of subjects so that the labels and controls can be populated.
'CR - modified 15/07/2009 to limit to subjects examined in selected year
'CR v5113 - excluded dummy subject 'ZZ'
strSubjectList = "SELECT DISTINCT LeaversGCSESubjectSummary.SubjectID, LeaversGCSESubjectSummary.Description," & _
" LeaversGCSESubjectSummary.Year, LeaversGCSESubjectSummary.Weighting" & _
" FROM LeaversGCSESubjectSummary" & _
" WHERE (((LeaversGCSESubjectSummary.SubjectID)<>'ZZ') AND ((LeaversGCSESubjectSummary.Year) = GetExamYear()))" & _
" ORDER BY LeaversGCSESubjectSummary.Description;"
'get fields for crosstab and 'fix' these in the SQL for the record source
Dim Flds As String
Flds = " In ("
Set db = CurrentDb
Set MySet = db.OpenRecordset(strSubjectList)
With MySet
If .RecordCount > 0 Then
.MoveLast
.MoveFirst
NumberOfSubjects = .RecordCount
'determine column width 'CR v4633W
'reduced min size v5191
SGW = AllSubjectGridWidth / NumberOfSubjects 'CR v4633W - width of each subject column
'If SGW > 0.37 Then SGW = 0.37 'set max size
If SGW > 0.5 Then
SGW = 0.5 'set max size
ElseIf SGW < 0.318 Then
SGW = 0.318 'set min size
Else
SGW = SGW 'set as calculated
End If
intCount1 = 1
Do Until .EOF
Flds = Flds & "'" & !SubjectID & "', "
'Debug.Print flds
Me("Text" & intCount1).ControlSource = Replace(!SubjectID, ".", "_")
Me("Text" & intCount1).visible = True
'Me("Text" & intCount1).Left = (7.1 + (0.35 * intCount1)) * TwipsNumber
Me("Text" & intCount1).Left = (6.35 + (SGW * intCount1)) * TwipsNumber
Me("Text" & intCount1).Width = SGW * TwipsNumber 'CR v5116
With Me("Text" & intCount1).FormatConditions
.Delete
'Set traffic light for residuals
Set Fcn = .Add(acFieldValue, acLessThanOrEqual, -12)
Fcn.ForeColor = vbWhite
Fcn.BackColor = vbRed
' 'fc.FontBold = True
Set Fcn = .Add(acFieldValue, acBetween, -6, -11)
Fcn.ForeColor = vbBlack
Fcn.BackColor = 39423 'amber
' 'fc.FontBold = True
Set Fcn = .Add(acFieldValue, acGreaterThanOrEqual, 6)
Fcn.ForeColor = vbWhite
Fcn.BackColor = vbGreen '
' 'fc.FontBold = True
End With
Me("Label" & intCount1).visible = True
'Me("Label" & intCount1).Left = (7.1 + (0.35 * intCount1)) * TwipsNumber
Me("Label" & intCount1).Left = (6.35 + (SGW * intCount1)) * TwipsNumber
Me("Label" & intCount1).Width = SGW * TwipsNumber 'CR v5116
Me("Label" & intCount1).Caption = " " & Replace(!Description, "&", "&&")
Me("Subj" & intCount1).visible = True
'Me("Subj" & intCount1).Left = (7.1 + (0.35 * intCount1)) * TwipsNumber
Me("Subj" & intCount1).Left = (6.35 + (SGW * intCount1)) * TwipsNumber
Me("Subj" & intCount1).Width = SGW * TwipsNumber 'CR v5116
'Me("Subj" & intCount1).Caption = !SubjectID
Me("Subj" & intCount1).Caption = Nz(!Weighting, "") 'CR v4557W
'==========================
'CR - Subject totals added v4557W
strCriteria = "Year = " & intYear & " And SubjectID = '" & !SubjectID & "'"
'Debug.Print strCriteria
'Calculate subject entries
strText1 = DLookup("Entries", "LeaversGCSESubjectSummary", strCriteria)
'Me("TCount" & intCount1).Left = (7.1 + (0.35 * intCount1)) * TwipsNumber
Me("TCount" & intCount1).Left = (6.35 + (SGW * intCount1)) * TwipsNumber
Me("TCount" & intCount1).Width = SGW * TwipsNumber 'CR v5116
Me("TCount" & intCount1).Caption = CInt(Nz(strText1, 0))
Me("TCount" & intCount1).visible = True
'Calculate subject %A*C
strText2 = DLookup("[%A*-C]", "LeaversGCSESubjectSummary", strCriteria)
'Me("TSum" & intCount1).Left = (7.1 + (0.35 * intCount1)) * TwipsNumber
Me("TSum" & intCount1).Left = (6.35 + (SGW * intCount1)) * TwipsNumber
Me("TSum" & intCount1).Width = SGW * TwipsNumber 'CR v5116
Me("TSum" & intCount1).Caption = CInt(Nz(strText2, 0))
Me("TSum" & intCount1).visible = True
'=========================
intCount1 = intCount1 + 1
'Me.LineHeader.Width = (7.1 + (0.35 * intCount1))
Me.LineHeader.Width = (6.35 + (SGW * intCount1))
.MoveNext
Loop
Else
'nothing
End If
.Close
End With
'create In statement and append to StrSQL1 as the record source
Flds = Left(Flds, Len(Flds) - 2) & ")"
'Debug.Print Me.RecordSource
Exit_Handler:
Exit Sub
Err_Handler:
If Err.Number = 2465 Then
MsgBox "This report does not have enough columns" & _
" to display all " & NumberOfSubjects & " subjects ", vbExclamation
Exit Sub
Else
'create error message & log
strProc = "Report_Open"
PopulateErrorLog
Resume Exit_Handler
End If
End Sub