By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,193 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Tab Control

P: n/a
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

Jun 1 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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

Jun 2 '06 #2

P: n/a
The code doesn't work; I get the "#Name?" error. The main form is
bound to the Task and Subtask tables. If I bound it only to the Task
table, I get a request for parameter Subtasks.SubtaskId. If I bound
the form to all 3 tables, I'm not able to add new records. I am still
not able to add multiple subtasks to one task. The new record comes
up; but the taskId for the new record is not the same (it is 0). I get
the following error when I try to add a 2nd subtask to correspond with
the previous task: "The LinkMasterFields property setting has produced
this error: 'The object doesn't contain the Automation object 'TaskID."
Allen Browne wrote:
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


Jun 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.