in the code below...
if tf is False frmGrade recordsource changes from tblGrade to tblGradeCopy ( a local copy of tblGrade)
i added this code to insert new records in tblGradeCopy:
docmd.RunSQL ("insert into tblGradeCopy (fldExamId) values(4)")
...however the subform does not show these added records.
Any ideas why? please help, thank you so much!
CODE
Function ExamRecordSource(tf As Boolean)
Select Case tf
Case True
With Form_frmExam
.RecordSource = "tblExam"
.RecordSelectors = False
.cntClass.ControlSource = "fldClassId"
.cntSection.ControlSource = "fldSectionId"
.cntClass.RowSource = "select fldClassId,fldClass from tblClass"
.cntSection.RowSource = "select fldSectionId,fldSection from tblSection"
.AllowAdditions = False
End With
With Form_frmGrade
.RecordSource = "tblGrade"
.cntExamId.ControlSource = "fldExamId"
.cntStudentId.ControlSource = "fldStudentId"
.AllowEdits = False
End With
Case False
With Form_frmExam
.RecordSource = ""
.RecordSelectors = False
.cntClass.ControlSource = ""
.cntSection.ControlSource = ""
.cntClass.RowSource = "select fldClassId,fldClass from tblClass"
.cntSection.RowSource = "select fldSectionId,fldSection from tblSection"
.cntClass = ""
.cntSection = ""
.AllowEdits = True
End With
With Form_frmExam.frmGrade
DoCmd.RunSQL ("delete from tblGradeCopy")
docmd.RunSQL ("insert into tblGradeCopy (fldExamId) values(4)")
.Form.RecordSource = "tblGradeCopy"
.Controls("cntExamId").ControlSource = "fldExamId"
.Controls("cntStudentId").ControlSource = "fldStudentId"
.Form.AllowAdditions = True
.Form.DataEntry = False
.Requery
End With
End Select
End Function
Select Case tf
Case True
With Form_frmExam
.RecordSource = "tblExam"
.RecordSelectors = False
.cntClass.ControlSource = "fldClassId"
.cntSection.ControlSource = "fldSectionId"
.cntClass.RowSource = "select fldClassId,fldClass from tblClass"
.cntSection.RowSource = "select fldSectionId,fldSection from tblSection"
.AllowAdditions = False
End With
With Form_frmGrade
.RecordSource = "tblGrade"
.cntExamId.ControlSource = "fldExamId"
.cntStudentId.ControlSource = "fldStudentId"
.AllowEdits = False
End With
Case False
With Form_frmExam
.RecordSource = ""
.RecordSelectors = False
.cntClass.ControlSource = ""
.cntSection.ControlSource = ""
.cntClass.RowSource = "select fldClassId,fldClass from tblClass"
.cntSection.RowSource = "select fldSectionId,fldSection from tblSection"
.cntClass = ""
.cntSection = ""
.AllowEdits = True
End With
With Form_frmExam.frmGrade
DoCmd.RunSQL ("delete from tblGradeCopy")
docmd.RunSQL ("insert into tblGradeCopy (fldExamId) values(4)")
.Form.RecordSource = "tblGradeCopy"
.Controls("cntExamId").ControlSource = "fldExamId"
.Controls("cntStudentId").ControlSource = "fldStudentId"
.Form.AllowAdditions = True
.Form.DataEntry = False
.Requery
End With
End Select
End Function