Tab Control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dBNovice

    #1

    Tab Control

    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 cmdAddNewSubtas k_Click()
    On Error GoTo Err_cmdAddNewSu btask_Click

    DoCmd.GoToRecor d , , acNewRec
    Forms!Tasks!Sub Tasks1!TaskID = Me.TaskID

    Exit_cmdAddNewS ubtask_Click:
    Exit Sub

    Err_cmdAddNewSu btask_Click:
    MsgBox Err.Description
    Resume Exit_cmdAddNewS ubtask_Click

    End Sub

  • Allen Browne

    #2
    Re: Tab Control

    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 LinkMasterField s 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 LinkMasterField s 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 LinkMasterField s property to:
    txtSubTaskID
    and set its LinkChildFields to:
    SubTaskID

    In your code, the line:
    Forms!Tasks!Sub Tasks1!TaskID = Me.TaskID
    is unnecessary. If you have the LinkMasterField s/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" <luv4nrt@hotmai l.com> wrote in message
    news:1149201659 .738345.140900@ c74g2000cwc.goo glegroups.com.. .[color=blue]
    > 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 cmdAddNewSubtas k_Click()
    > On Error GoTo Err_cmdAddNewSu btask_Click
    >
    > DoCmd.GoToRecor d , , acNewRec
    > Forms!Tasks!Sub Tasks1!TaskID = Me.TaskID
    >
    > Exit_cmdAddNewS ubtask_Click:
    > Exit Sub
    >
    > Err_cmdAddNewSu btask_Click:
    > MsgBox Err.Description
    > Resume Exit_cmdAddNewS ubtask_Click
    >
    > End Sub[/color]


    Comment

    • dBNovice

      #3
      Re: Tab Control

      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.Subtas kId. 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 LinkMasterField s property setting has produced
      this error: 'The object doesn't contain the Automation object 'TaskID."
      Allen Browne wrote:[color=blue]
      > 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 LinkMasterField s 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 LinkMasterField s 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 LinkMasterField s property to:
      > txtSubTaskID
      > and set its LinkChildFields to:
      > SubTaskID
      >
      > In your code, the line:
      > Forms!Tasks!Sub Tasks1!TaskID = Me.TaskID
      > is unnecessary. If you have the LinkMasterField s/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" <luv4nrt@hotmai l.com> wrote in message
      > news:1149201659 .738345.140900@ c74g2000cwc.goo glegroups.com.. .[color=green]
      > > 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 cmdAddNewSubtas k_Click()
      > > On Error GoTo Err_cmdAddNewSu btask_Click
      > >
      > > DoCmd.GoToRecor d , , acNewRec
      > > Forms!Tasks!Sub Tasks1!TaskID = Me.TaskID
      > >
      > > Exit_cmdAddNewS ubtask_Click:
      > > Exit Sub
      > >
      > > Err_cmdAddNewSu btask_Click:
      > > MsgBox Err.Description
      > > Resume Exit_cmdAddNewS ubtask_Click
      > >
      > > End Sub[/color][/color]

      Comment

      Working...