Create a New Record on One to Many custom form

megamef

Registered User.
Local time
Today, 09:43
Joined
Apr 18, 2013
Messages
161
Hi All,

I have 2 tables that have a one to many relationship between them.

Table 1 is the details table (this information never needs to change) and Table 2 is the records table (a new record will be created every year).

So for example:

TABLE 1
ID ¦ Item ¦ Brand ¦ Units ¦ Model ¦ Serial
1 ¦ Thermometer ¦ DegC ¦ TempCompany ¦ A100 ¦ 123ABC
2 ¦ Hygrometer ¦ Rh% ¦ WaterCompany ¦ B100 ¦ 456DEG

TABLE 2

RecID ¦ RecDate ¦ Measurement ¦ UniqueNumber
1 ¦ 05/05/14 ¦ 25.3 ¦ 4
2 ¦ 05/05/14 ¦ 40.5 ¦ 3
1 ¦ 05/05/13 ¦ 22.1 ¦ 2
1 ¦ 05/05/12 ¦ 23.4 ¦ 1

This works.

But what I want now is to make a form so that the user can add a new record in TABLE 2 based on the ID number in Table 1.

So as an example:

click a combo box on a form that only selects either ID 1 or 2 from TABLE 1 and then makes a new record in TABLE 2 so the user can add this year's measurements.

I can't work out how to do this.

Any ideas?
 
If I'm understanding correctly, you would want a ComboBox, a TextBox, and a Command Button.
In the Command Button OnClick event use this:

Code:
CurrentDb.Execute"INSERT INTO Table2(RecID, RecDate, Measurement) VALUES(" & Me.cboRecord & ", Date(), " & Me.txtMeasurement & ")"

If your Measurement field is Text, you would need to add single quotes around the Me.txtMeasurement like so:

Code:
'" & Me.txtMeasurement & "'
 

Users who are viewing this thread

Back
Top Bottom