Unable to open form with a field populated, error

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have form1 that pulls up student id & info. It includes a subform that
displays all of the students lunch transaction from table B. I have an 'add
transaction button' which allows entries of new lunch transactions into table
B. Instead of a blank form, I've stored the student id value from form1 into
the 'add transaction' form (so that I do not have to consistently enter the
id), but get an error when I try to save. I believe it is because you cannot
have duplicates in Table A. But I am trying to add a transaction to Table B.
How can I extract the student id from form 1 and insert the value in the
student id field (as if I have entered it) in the 'add transaction' form? In
the 'transaction entry form' in the student id data control, I had
=Forms![Form1].[studentid]. The form is pulled up with the student id but
cannot save, error "You cannot add / change record because a related record
is required in Table A". ? Thanks!

tokyo681
 
This sounds like you have an unbound subform; that is, your LinkChildFields
and LinkMasterFields properties of the subform control are blank.

The way subforms work best is to realize that Student is the mainform and
StudentLunch is the subform. So if you have a Student table, there might be
a StudentID field which is unique (the primary key.) Then there could also
be a StudentLunch table which contains a StudentLunchID field and a
StudentID field. The StudentID field is a Foreign-key referencing the
StudentID field in the Student table.
So if you start over and make a new Autoform for the Student table, then in
design view you can literally drag the StudentLunch table onto the form and
it will properly tie it in as a subform control. You can look at the
subform control properties (LinkChildFields and LinkMasterFields) and they
should both be set to StudentID. This is the quickest way to make a useable
subform.
 
Back
Top