Results 1 to 4 of 4
  1. #1
    Lounger
    Join Date
    Nov 2005
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Link Subforms (2003)

    I am trying to add two subforms to a form. I have already created the subforms.
    Instead of using the wizard and having the subforms open with the form I would like to have a button (when clicked) open the subform from the main form. I know you can do this in the wizard, but the wizard will only allow you to create one subfrom using this method.

    I also tried using the wizard and putting in a command button to open the subform. I thought that had worked but when I entered the data and try to go to the next record (in the subform) it says "You cannot add or change a reacord because a related record is required in table customer profile screen" (which the main form is based off of)

    Any help with this would be greatly appreciated.

    Thanks,

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Link Subforms (2003)

    Technically, a subform is part of the main form, while a form that is opened by clicking a button is called a popup form.

    Subforms can be linked to the main form they are part of by setting their Link Master Fields and Link Child Field properties; no VBA code is needed.
    But a popup form doesn't have a property to link it to the main form, so you have to write VBA code to handle this.

    If you'd like to avoid VBA, it's best to use (real) subforms. If you want to create more than one subform and have limited space, you could use a tab control on the main form and place each subform in its own tab page.

    If you prefer using a popup form, you can find an example of the type of code you need in <post#=661,170>post 661,170</post#> (the attachment to that post is missing, but the code is listed in the post itself).

  3. #3
    Lounger
    Join Date
    Nov 2005
    Posts
    48
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Link Subforms (2003)

    Thanks! I decided just to use the tab control. It was the easiest way to go.

    Now I have created a report using the main form and the two subforms. It worked very nice, but now I am not sure how to get the report to just print one record.

    Ideally I would like to put a print button on the form and have the report print for just that one record. Any ideas?

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Link Subforms (2003)

    Does the table behind the main form have a field that uniquely identifies the records, for example an AutoNumber field?

    If so, you can use code like this in the On Click event procedure of the command button:
    <code>
    Private Sub cmdReport_Click()
    DoCmd.OpenReport ReportName:="rptSomething", View:=acViewPreview, WhereCondition:="ID=" & Me.ID
    End Sub
    </code>
    where:
    cmdReport is the name of the command button.
    rptSomething is the name of the report to be opened.
    ID is the name of the field that identifies the records uniquely (I have assumed that it is a number field).

Posting Permissions

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