Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2006

    Unanswered: How to put forms inside tab? and link 2 forms?

    Hi again, i have previously asked this question
    I have main form called Patient
    Subform that shows Illness of each visit of that patient (billID is primary key here)
    and A subform that called Analysis (or LabTest) which shows medication of each visit. (BillID is foriegn key), it is 1:M relationship as each visit may have one or many lab tests (e.g. blood test)

    Now, I tough it would be better if I use two tabs, first tab will have all forms except Analysis form, and the second tab will have analysis subform as it will be used rarely...

    I created a tab but didn't know how to put the forms inside that tab? coz I can see the forms on both tabs so it is not working

    In addition, How can I link form Analysis that will exist in tab2 to subform that exists in tab1?

  2. #2
    Join Date
    Mar 2009
    Provided Answers: 14
    Usually I create a form that acts as a container and a dispatcher for the subforms. This "Parent" form has a Tab control with several tabs and each tab contains a subform.

    The Tab control nor any of its Tabs is a container in itself. You must place a SubForm/SubReport control on each Tab. I then use the SourceObject of these SubForm/SubReport controls to link them to a subform.

    The "Parent" form receives various messages sent by its "Children" (i.e. the subforms", processes them and, if necessary, notify other subforms. One example of this mechanism being that one of the subform acts as the "record selector" (i.e. you chose the current record from it). When the current record changes on this subform, it notifies the "Parent" form, sending the Id of the new current record, the "Parent" form then notifies the other "children" forms that changes their current record accordingly, or apply a filter on their own recordset.

    A basic illustration of this mechanism goes as follows:

    a) SubForm1 is the "record selector" it uses 'TableOne' as its RecordSource.

    b) SubForm2 uses 'TableMany' as its RecordSource.

    c) 'TableMany' is on the "Many" side of a relationship with 'TableOne' through its 'FK_TableOne' column related to the primary key of 'TableOne": 'PK_TableOne'. The query that expresses this is:
    SELECT TableOne.*, 
    FROM   TableOne LEFT JOIN 
           TableMany ON TableOne.PK_TableOne = TableMany.FK_TableOne;
    d) 'FormParent' Is the "Parent" form. It has a TabControl control with two Tabs: 'Tab1' and 'Tab2'. Each Tab has a SubForm/SubReport control:
    'Child1' is the SubForm/SubReport control on 'Tab1' and its SourceObject value is 'SubForm1', while 'Child2' is the SubForm/SubReport control on 'Tab2' and its SourceObject value is 'SubForm2'.

    1. In the module of 'SubForm1':
    Private Sub Form_Current()
        If HaveParent = True Then Me.Parent.Notify "RowChanged", Me.PK_TableOne.Value
    End Sub
    Private Function HaveParent() As Boolean
        Dim frm As Form
        HaveParent = True
        For Each frm In Application.Forms
            If frm.Name = Form.Name Then
                HaveParent = False
                Exit For
            End If
    End Function
    2. In the module of 'FormParent':
    Public Sub Notify (ByVal Message as String, ByVal RowId As Long)
        Const c_strRecordSource As String = "SELECT * FROM TableMany WHERE FK_TableOne = @Id"
        If Message = "RowChanged" Then
        ' In a real application there would be other messages, hence the test.
            Me.Child2.Form.RecordSource = Replace(c_strRecordSource, "@Id", RowId)
        End If
    Have a nice day!

  3. #3
    Join Date
    Aug 2006
    Sinnhdu, Thanks a lot for the help and explanation, I appreciate it.
    I am experimenting with your explanation, I'll get back if I have a problem

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts