Adding Records to Sub-Form by Default

N

NFL

I have a form based on 2-Tables (1 to many). Whenever I create a new record,
I would like the subform to automatically add 5 entries in the subform. Is
that possible? The new records will be consistent every time I add a new
record to the main table.

Thank you,
 
J

John W. Vinson

I have a form based on 2-Tables (1 to many). Whenever I create a new record,
I would like the subform to automatically add 5 entries in the subform. Is
that possible? The new records will be consistent every time I add a new
record to the main table.

Thank you,

Well... it's generally A Bad Idea to add blank "placeholder" records assuming
that they will get filled in later. They often don't!

But if you want to do so, have code in the mainform's BeforeUpdate event to
check to see if the child table already has records, and if not, run an append
query to fill it. Knowing nothing about your forms or tables I can't really
suggest specific code.
 
N

NFL

Here's the snapshot of the talble
1st table 2nd Table
Student ID (number) Student ID (number (dups OK)
name course title
supervisor course name
phone schedule date
workcenter required (y/n)
Autonumber location
completed (y/n)
AutoNumber

When I click to add a new record, the 1st table will be all blanks for user
to complete. The 2nd table (sub-form) will show course requirements and as
a minimum add one field for each record Course Title) for new employees.
The required field is set to (y) as default. The other fields will have to
be manually entered. There are other course requirements based on position
and duties.

Thank you for your response!
 
J

John W. Vinson

Here's the snapshot of the talble
1st table 2nd Table
Student ID (number) Student ID (number (dups OK)
name course title
supervisor course name
phone schedule date
workcenter required (y/n)
Autonumber location
completed (y/n)
AutoNumber

When I click to add a new record, the 1st table will be all blanks for user
to complete. The 2nd table (sub-form) will show course requirements and as
a minimum add one field for each record Course Title) for new employees.
The required field is set to (y) as default. The other fields will have to
be manually entered. There are other course requirements based on position
and duties.

<puzzlement> This contradicts your prior request to have six records added to
the child table (some of which would presumably have to be deleted!)

The usual way to do this would be to have THREE tables, not two:

Students
StudentID <Primary Key>
LastName
FirstName
<other biographical and contact data>

Courses
CourseNo <Primary Key>
CourseTitle
CourseName
ScheduleDate
more info about the course as a thing in itself

Enrollment
StudentID <foreign key link to Students>
CourseNo <foreign key link to Courses>
DateEnrolled
Completed
<other info about THIS student in THIS course>

Note: if you have a unique, numeric, stable StudentID and CourseNo you do NOT
need a separate autonumber in those tables, just use the existing unique ID as
the primary key; fieldnames should best not contain blanks or special
characters; you should have separate first and last name fields (and maybe a
middlename or middleinitial field) so you can more easily search or sort by
one of the names.

You would want a Form based on Students with a Subform based on Enrollment;
there would be no need to "pre add" records, the subform will fill in the
student ID as part of the master/child link feature, and you'ld have a combo
box to select the course from the Courses table.
 

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