Calling a subform from button on main form

L

Lisa

Hi all,
I have a main form "student" and I want to call a subform "registration"
from that form via a button on the form. Right now I can get the button to
filter the results to show only the entries in "registration" for that
student, but I cannot add another entry in "registration" and have it
correspond to that student. Can anyone help me figure out how to call this
subform without imbedding it in the main form? Thank you!
 
G

Graham Mandeno

Hi Lisa

This is not a true subform, but let's call it a "consequent" form.

With a true subform, you have LinkMasterFields and LinkChildFields
properties which serve two purposes: they automatically filter the view of
the subform, limiting it to a particular value in a particular field (or
fileds), and they also automatically set the default value for that field
(or fields) to the link value.

With a consequent form, you need to look after that stuff manually.

Already you have done the first part - setting up the filter. For the
default value, I suggest you pass the StudentID via the OpenArgs property.
For example:

DoCmd.OpenForm "frmRegistration", _
WhereCondition := "[StudentID]=" & Me.StudentID, _
WindowMode := acDialog, _
OpenArgs := StudentID

Now, in the Form_Load event proc of you registration form, check OpenArgs
and set the DefaultValue property:

If Not IsNull(Me.OpenArgs) Then
Me.[YourStudentField].DefaultValue = """" & Me.OpenArgs & """"
End If
 
Top