G
Guest
Hi Guys,
I created a botton that enrols a student into a class. when I pressed the
botton, it works properly in data insert and delete level.
But Requery statement at the end of the code is not working properly.
Therefore, I need to manually requery the subform (manually requerying also
need to wait about 2-3 seconds to reflect the changes after the button is
pressed).
Could someone help me solve this problem?
Thanks in Advance.
Private Sub btnEnrolStudent_Click()
On Error GoTo Err_btnEnrolStudent_Click
If IsNull(Forms!frmStudent.Form.sid) Then
MsgBox "Enter Customer Information before Enrolling into Class."
Else
If MsgBox("Enrol Student?", vbQuestion + vbYesNo, "Confirm") = vbYes
Then
Dim intSID As Integer, intCID As Integer, strsql As String
intSID = Forms!frmStudent.Form.sid
If Me.TabCtlClass.Value = 0 Then
intCID = Forms!frmClass!fsubClassList.Form.cid
strsql = "INSERT INTO ENROL (sid, cid) " & "Values (" &
intSID & ", '" & intCID & "' )"
CurrentDb().Execute strsql, dbFailOnError
ElseIf Me.TabCtlClass.Value = 1 Then
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim rst1 As New ADODB.Recordset
Dim strg As String
Dim ttt As New ADODB.Command
strg = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\database\Korean Swimming.mdb;Persist Security Info=False"
conn.Open strg
rst.Open "SELECT C.cid FROM ENROL E, CLASS C WHERE E.cid =
C.cid AND E.sid = " & intSID & " AND C.ctype = 2", conn
If Not (rst.BOF Or rst.EOF) Then
intCID = rst.Fields("cid")
Else
strsql = "INSERT INTO CLASS (ctype) VALUES (2)"
ttt.ActiveConnection = conn
ttt.CommandText = strsql
ttt.ActiveConnection.BeginTrans
ttt.Execute
ttt.ActiveConnection.CommitTrans
rst1.Open "SELECT cid FROM CLASS WHERE ctype = 2 AND
is_on = Yes AND NOT EXISTS (select cid from ENROL where ENROL.cid =
CLASS.cid)", conn
If Not (rst1.BOF Or rst1.EOF) Then
intCID = rst1.Fields("cid")
End If
End If
strsql = "INSERT INTO ENROL (sid, cid) VALUES (" & intSID &
"," & intCID & ");"
CurrentDb().Execute strsql, dbFailOnError
Set rst = Nothing
Set rst1 = Nothing
Set conn = Nothing
End If
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmStudent"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!frmStudent!fsubEnrolmentList.Requery
<---------------------(here)
End If
End If
Exit_btnEnrolStudent_Click:
Exit Sub
Err_btnEnrolStudent_Click:
MsgBox Err.Description
Resume Exit_btnEnrolStudent_Click
End Sub
I created a botton that enrols a student into a class. when I pressed the
botton, it works properly in data insert and delete level.
But Requery statement at the end of the code is not working properly.
Therefore, I need to manually requery the subform (manually requerying also
need to wait about 2-3 seconds to reflect the changes after the button is
pressed).
Could someone help me solve this problem?
Thanks in Advance.
Private Sub btnEnrolStudent_Click()
On Error GoTo Err_btnEnrolStudent_Click
If IsNull(Forms!frmStudent.Form.sid) Then
MsgBox "Enter Customer Information before Enrolling into Class."
Else
If MsgBox("Enrol Student?", vbQuestion + vbYesNo, "Confirm") = vbYes
Then
Dim intSID As Integer, intCID As Integer, strsql As String
intSID = Forms!frmStudent.Form.sid
If Me.TabCtlClass.Value = 0 Then
intCID = Forms!frmClass!fsubClassList.Form.cid
strsql = "INSERT INTO ENROL (sid, cid) " & "Values (" &
intSID & ", '" & intCID & "' )"
CurrentDb().Execute strsql, dbFailOnError
ElseIf Me.TabCtlClass.Value = 1 Then
Dim conn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim rst1 As New ADODB.Recordset
Dim strg As String
Dim ttt As New ADODB.Command
strg = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\database\Korean Swimming.mdb;Persist Security Info=False"
conn.Open strg
rst.Open "SELECT C.cid FROM ENROL E, CLASS C WHERE E.cid =
C.cid AND E.sid = " & intSID & " AND C.ctype = 2", conn
If Not (rst.BOF Or rst.EOF) Then
intCID = rst.Fields("cid")
Else
strsql = "INSERT INTO CLASS (ctype) VALUES (2)"
ttt.ActiveConnection = conn
ttt.CommandText = strsql
ttt.ActiveConnection.BeginTrans
ttt.Execute
ttt.ActiveConnection.CommitTrans
rst1.Open "SELECT cid FROM CLASS WHERE ctype = 2 AND
is_on = Yes AND NOT EXISTS (select cid from ENROL where ENROL.cid =
CLASS.cid)", conn
If Not (rst1.BOF Or rst1.EOF) Then
intCID = rst1.Fields("cid")
End If
End If
strsql = "INSERT INTO ENROL (sid, cid) VALUES (" & intSID &
"," & intCID & ");"
CurrentDb().Execute strsql, dbFailOnError
Set rst = Nothing
Set rst1 = Nothing
Set conn = Nothing
End If
Dim stDocName As String
Dim stLinkCriteria As String
stDocName = "frmStudent"
DoCmd.OpenForm stDocName, , , stLinkCriteria
Forms!frmStudent!fsubEnrolmentList.Requery
<---------------------(here)
End If
End If
Exit_btnEnrolStudent_Click:
Exit Sub
Err_btnEnrolStudent_Click:
MsgBox Err.Description
Resume Exit_btnEnrolStudent_Click
End Sub