How I pass a value from a form to a subform?

E

Egyptkm

I am creating a student database in which I have a form (displayed as a
continuous form) that lists the terms that the student were enrolled in the
school. Beside each term that the student is enrolled, there is a button
that links to a subform where I want to enter the courses that the student
was enrolled for the corresponding term. I have been unable to successfully
link the "termid" field (numeric field) from the main form to the "termid"
field in the subform. When I click on the subform button beside each of the
terms, the "termid" field in the subform is blank instead of displaying the
corresponding "termid" field from the main form. Below is the coding from
the subform button:

Private Sub CourseEnroll_Click()
On Error GoTo Err_CourseEnroll_Click

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "sfrm2_courses"

DoCmd.OpenForm stDocName, acNormal, , "[termid]=" & Me.termid

Exit_CourseEnroll_Click:
Exit Sub

Err_CourseEnroll_Click:
MsgBox Err.Description
Resume Exit_CourseEnroll_Click

End Sub


Thanks for your help.

-Karen
 
R

richard harris

hi, you are trying to link to a form that has no value to link to. what you
need is an event in the before insert command of the sub form, so that when
you enter a vlaue in one of the fields the form will auto transfer the id
value from the main form. t he man form needs to remain open to pass this
value

the code is

Private Sub Form_BeforeInsert(Cancel As Integer)

With Forms![yourmainform]
If Not IsNull(!yourid) Then
Me.yourid= !yourid
End With
End Sub

i am not sure if this willwork from a continious form, if not it may be
worth linking from yourmain form to a single form containing the specific
data and then opening your sub form ti add the additonal data.

i hope this helps

richard
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top