Full Version: Subform.RecordSource
UtterAccess Discussion Forums > Microsoft® Access > Access Forms
ALMU3YN
hi, i created a main form frmExam and a subform frmGrade.
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
Scott McDaniel
Is fldExamID the link field between tblGradeCopy and table on which the parent form is based? If so, have you properly set your Master/Child links on the subform control to reflect this?

Is "frmExam" the Parent form? If so, you're setting the Recordsource of that form to nothing ... if you have set the Master/Child links properly, then this would, of course, show no records (since the Parent record would be nothing, the Child records would also be nothing). Try setting the RecordSource of frmExam to something (perhaps the same as if your SElect Case is True) and see if the records show up.
ALMU3YN
Thank you Scott for your reply.

fldExamID is NOT the link between tblGradeCopy and tblExam.

It is the link between tblGrade and tblExam.

frmExam is the parent form, frmGrade is the subform.

I'm only using tblGradeCopy [local copy of tblGrade] to add new exmas.

That is why i set frmGrade recordsource to tblGradeCopy then switch the recordsource back to tblGrade.

In my BE, i've created a relationship between tblExam and tblGrade [linked field fldExamId].

i set the frmGrade recordsource to tblGradeCopy also for the same reason of adding an exam

and setting the grades for all students in this Class/Section.

[ moving the data from tblGradeCopy to tblGrade is simple, whatever in frmExam goes to tblExam. whatever is

in tblGradeCopy goes to tblGrade having same fldExamId as the Exam Id in frmExam]

Edited by: ALMU3YN on Wed Apr 8 12:12:04 EDT 2009.

Edited by: ALMU3YN on Wed Apr 8 12:15:11 EDT 2009.
ALMU3YN
I created a relationship between a local tblExamCopy and tblGradeCopy.
i then set frmExam recordsource=tblExamCopy
and frmGrade recordsource=tblGradeCopy
In order to save i use two runSQL commands.
One puts tblExamCopy in tblExam and the other tblGradeCopy in tblGrade.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.