Add multi entries

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

Guest

I am doing tests on plates & would like to add 5 records to two different
tables from a form.
To start with the user opens a form ‘frm_Batch-No’, this form has two
sub-forms bound to their respective individual tables that take the length &
width dimensions for 5 consecutive plates, one table take the measurements
before they are fired(frm_Form-Dimns) & the other after they are fired
(frm_Sinter-Dims).
Can any one advise on how I populate the two sub forms with values from 1 to
5.
Also the two sub-forms are set to Datasheet view.

Table definitions are as follows with a one to many relation on
tbl_Batch-No Test_id to Test_id in tbl_Form-Dimns & tbl_Sinter-Dims

tbl_Batch-No
Test_id Autonumber(Unique record) Primary Key
Batch_id (Number user enters on form)
Date Tested

tbl_Form-Dimns
ID Autonumber(Unique record)
Test_id (replicated from Above table)
PlateNo (Plate number being tested) this is what I want to add in
automatically
Len (Plate length)
Wid (Plate Width)

tbl_Sinter-Dims
ID Autonumber(Unique record)
Test_id (replicated from Above table)
PlateNo (Plate number being tested) auto fill as above
Len (Plate length)
Wid (Plate Width)
 
Question:
When the user opens frm_Batch_no, do they create a new batch record or are
they looking up an existing batch record?
The reason for the question is it would make a difference on where you do it.

The basic answer is, you will need some VBA code to create the new records
for the sub forms. If you are going to create the records for the sub forms
when you first create batch records, then I would suggest you put your code
in the After Insert event of the Main Form. If it is to create them for an
existing batch record, I think you might do it in the current event of the
main form. In either case, you will want to first check for existing records
before you try to create them
 
Klatuu,
Yes, when the user opens the form they do create a new batch record &
test_id is passed to the two sub forms, one test_id to many in the two forms/
tables i.e.
user has measured 5 plates of batch 1200, s/he opens the form & adds 1200 in
the Batch# & todays date in the date field, tabs over to the sub form to
plateno & enters 1 for plate 1 then enters the length & width. They continues
to enter all the plateno's length & width for the remaining 4 plates. This is
exactly the same process on the sub form for the frm_Sinter-Dims form but has
differant length & width figures.
Again, what I would like to see is the sub forms already loaded with a value
from 1 to 5 relating to the plate numbers so that the user does not have to
enter them as they do now.
 
Okay, then you need to create the records in the After Insert Event of the
main form. Here is the basic concept:

Dim rst as Recordset
Dim intRecs as Integer

Set rst = CurrentDb.OpenRecordset("TableName", dbOpenDynaset)
With rst
For intRecs = 1 to 5
.AddNew
!SomeVariable = The Batch Number
!SomeOtherVariable = intRecs ' The Plate Number
.Update
Next intRecs
.Close
End With
Set rst = nothing

You will need to fill out the details, and you need to to this for both
tables.
 
Back
Top