RE: Xếp phòng thi
duynamvnn1208 > 26-09-18, 01:25 PM
Của bạn đây. Dùng nguyên cái Code này thay vào là được.
Dạo này ko thấy chèn php ntn nhỉ?
Private Sub cmdphongthi_Click()
Dim areaNum As Integer
For areaNum = 1 To DMax("khuvuc", "tblDisplay")
setClassNumber areaNum
Next areaNum
End Sub
Sub setClassNumber(area As Integer)
Dim rst1 As DAO.Recordset
Dim rst2 As DAO.Recordset
Dim normalClass As Integer
Dim specialClass As Integer
Dim dCount As Integer
Dim class As Integer
Dim dCount2 As Integer
Set rst1 = CurrentDb.OpenRecordset("tblmamon")
class = 1
Do While Not rst1.EOF
Set rst2 = CurrentDb.OpenRecordset("SELECT * FROM tblDisplay WHERE mamon = '" & rst1!mamon & "' AND khuvuc = '" & area & "'")
rst2.MoveLast
normalClass = Int(rst2.RecordCount / Me.txtsots)
specialClass = (rst2.RecordCount Mod Me.txtsots + Me.txtsots) / 2
rst2.MoveFirst
dCount = 0
dCount2 = 1
Do While Not rst2.EOF
If dCount2 < normalClass Then
rst2.Edit
rst2!Phong = Format(class, "00")
rst2.Update
dCount = dCount + 1
If dCount = Me.txtsots Then
dCount2 = dCount2 + 1
class = class + 1
dCount = 0
End If
Else
rst2.Edit
rst2!Phong = Format(class, "00")
rst2.Update
dCount = dCount + 1
If dCount = specialClass Then
dCount2 = dCount2 + 1
class = class + 1
dCount = 0
End If
End If
rst2.MoveNext
Loop
rst1.MoveNext
Loop
End Sub