J
Jason Kearns
Hello,
I have a form to enter student marks into a database. The form is set
up so the user selects the Teacher, Class, and Assignment from combo
boxes. After these three have been selected, a subform (continuous)
becomes visible showing all the students in this class with a textbox
for their mark next to each student's name. In addition to this, I
have a table called tblLockMarks, which has three fields, CurrentYear
(holds a year), Semester1Lock (Y/N), and Semester2Lock (Y/N). The
purpose of this table is so that the administration can "lock" all of
the marks so that teachers cannot go back and change marks after they
"lock down" the database for a given semester (I realize that this
"security" is minimal at best, but it is all I need). When a user
clicks on a Teacher/Class/Assignment, I know the CurrentYear, and I
also know if the assignment was given in Semester1 or Semester2 in the
bound subform. What I want to do, is then modify the subform's
properties so that the StudentMark text boxes are Locked (i.e.
Me.StudentMark.Locked = True) if the Semester has been "locked." I
have the following code, but I can't figure out on what form event to
call it (Open - No, Load - No).
Private Sub Form_Open()
On Error GoTo Err_Form_Open
If Forms!frmEnterMarks!sbfrmStudentMarks.Visible Then
Dim iYear As Integer
Dim oRs As ADODB.Recordset
Dim oConn As ADODB.Connection
Dim sSQL As String
Dim bSemester1 As Boolean
Dim bSemester2 As Boolean
iYear = Me.CurrYear.Value
Set oRs = New ADODB.Recordset
Set oConn = CurrentProject.Connection
sSQL = "SELECT * FROM tblLockMarks WHERE CurrYear = " & iYear &
";"
oRs.Open sSQL, oConn, adOpenStatic, adLockReadOnly
If oRs.EOF And oRs.BOF Then
Call ErrMsg("Serious error, no record for that year -
update table with current year", "Error")
Else
bSemester1 = oRs("LockSemester1")
bSemester2 = oRs("LockSemester2")
End If
If Me.MYPercentage.Value = 0 Then 'this is how I know it is in
Semester 2
If bSemester2 Then
Me.StudentMark.Locked = True
Else
Me.StudentMark.Locked = False
End If
Else
If bSemester1 Then
Me.StudentMark.Locked = True
Else
Me.StudentMark.Locked = False
End If
End If
oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
End If
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Number & Err.Description
Resume Exit_Form_Open
End Sub
Does anyone know when I should call this code (or something similar),
or if this is even possible to do?
Thanks!
JK
I have a form to enter student marks into a database. The form is set
up so the user selects the Teacher, Class, and Assignment from combo
boxes. After these three have been selected, a subform (continuous)
becomes visible showing all the students in this class with a textbox
for their mark next to each student's name. In addition to this, I
have a table called tblLockMarks, which has three fields, CurrentYear
(holds a year), Semester1Lock (Y/N), and Semester2Lock (Y/N). The
purpose of this table is so that the administration can "lock" all of
the marks so that teachers cannot go back and change marks after they
"lock down" the database for a given semester (I realize that this
"security" is minimal at best, but it is all I need). When a user
clicks on a Teacher/Class/Assignment, I know the CurrentYear, and I
also know if the assignment was given in Semester1 or Semester2 in the
bound subform. What I want to do, is then modify the subform's
properties so that the StudentMark text boxes are Locked (i.e.
Me.StudentMark.Locked = True) if the Semester has been "locked." I
have the following code, but I can't figure out on what form event to
call it (Open - No, Load - No).
Private Sub Form_Open()
On Error GoTo Err_Form_Open
If Forms!frmEnterMarks!sbfrmStudentMarks.Visible Then
Dim iYear As Integer
Dim oRs As ADODB.Recordset
Dim oConn As ADODB.Connection
Dim sSQL As String
Dim bSemester1 As Boolean
Dim bSemester2 As Boolean
iYear = Me.CurrYear.Value
Set oRs = New ADODB.Recordset
Set oConn = CurrentProject.Connection
sSQL = "SELECT * FROM tblLockMarks WHERE CurrYear = " & iYear &
";"
oRs.Open sSQL, oConn, adOpenStatic, adLockReadOnly
If oRs.EOF And oRs.BOF Then
Call ErrMsg("Serious error, no record for that year -
update table with current year", "Error")
Else
bSemester1 = oRs("LockSemester1")
bSemester2 = oRs("LockSemester2")
End If
If Me.MYPercentage.Value = 0 Then 'this is how I know it is in
Semester 2
If bSemester2 Then
Me.StudentMark.Locked = True
Else
Me.StudentMark.Locked = False
End If
Else
If bSemester1 Then
Me.StudentMark.Locked = True
Else
Me.StudentMark.Locked = False
End If
End If
oRs.Close
oConn.Close
Set oRs = Nothing
Set oConn = Nothing
End If
Exit_Form_Open:
Exit Sub
Err_Form_Open:
MsgBox Err.Number & Err.Description
Resume Exit_Form_Open
End Sub
Does anyone know when I should call this code (or something similar),
or if this is even possible to do?
Thanks!
JK