Presumably you have 3 tables:
- Task, with TaskID primary key.
- SubTask, with SubTaskID primary key, and TaskID foreign key.
- Element, with ElementID primary key, and SubTaskID foreign key.
Now you have a form that is bound to the Task table.
The fields of this table appear on page 0 of the tab control.
On page 1 of the tab control, you have a subform bound to the SubTask table.
The LinkMasterFields and LinkChildFields properties of the subform control
connect it correctly, based on the TaskID in the main form, and the TaskID
in the subform.
On page 2 of the tab control, you are trying to put another subform bound to
the Element table. There is no SubTaskID on the main form, so you cannot set
the LinkMasterFields property, and so this subform doesn't work.
It that's what is going on, add a text box to the main form, and give it
these properties:
Name txtSubTaskID
Control Source =[SubTask].[Form]![SubTaskID]
Format General Number
Visible No
You can now set the 2nd subform's LinkMasterFields property to:
txtSubTaskID
and set its LinkChildFields to:
SubTaskID
In your code, the line:
Forms!Tasks!SubTasks1!TaskID = Me.TaskID
is unnecessary. If you have the LinkMasterFields/LinkChildFields properties
of the subform control set correctly, the subform will automatically inherit
the value from the parent form.
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users -
http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"dBNovice" <lu*****@hotmail.com> wrote in message
news:11**********************@c74g2000cwc.googlegr oups.com...
Hello All,
I could really use some serious help with this one...
I have a form that has a tab control with 3 pages. Page(0) is Tasks,
Page(1) is SubTasks, and Page(2) is Elements. Page (1) is a subform of
page (0); linked with TaskID and page (2) is a subform of page (1);
linked with SubtaskID. I want to be able to have multiple subtasks for
some tasks; and multiple elements for some subtasks. The relationship
has been set accordingly; however when I try to add a second
corresponding record I am not able to retain the linked ID. For
instance, i have a task and want to make 2 subtasks. I can get the
first subtasks linked to the task but when I navigate to a new subtask
record, the taskId becomes 0 (not the previous/correct value). I tried
using the following code but it doesn't work.
Private Sub cmdAddNewSubtask_Click()
On Error GoTo Err_cmdAddNewSubtask_Click
DoCmd.GoToRecord , , acNewRec
Forms!Tasks!SubTasks1!TaskID = Me.TaskID
Exit_cmdAddNewSubtask_Click:
Exit Sub
Err_cmdAddNewSubtask_Click:
MsgBox Err.Description
Resume Exit_cmdAddNewSubtask_Click
End Sub