How To Link Subforms To Parent

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jeroen3131
    New Member
    • Oct 2014
    • 33

    How To Link Subforms To Parent

    [z{This post is in answer to a secondary question asked in:
    Database Design Post #6}]
    ------------------------


    Almost correct! The big picture isn't actually connected to the parts in the databse. The purpose of the big picture is to show the employee where to put the parts in the machine. Also small instructions like "Put grease here" are editted on the picture with MS Paint.

    I'm new to subforms but It seems very logical to me so I'm going to give it a try. I will post an update if I stumble upon some difficulties or it's a succes.

    Cheers!
    Last edited by zmbd; Oct 28 '14, 02:29 PM. Reason: [z{finishing the back link}]
  • Jeroen3131
    New Member
    • Oct 2014
    • 33

    #2
    Ok so now I have a MainForm with 4 subforms. Each subform has one textbox for Qty and one combobox with PartID and PartDescription as rowsource. To where should I set the controlsources for these boxes?

    I also set the tblSteps as Recordsource for my Maintable. When I press the Add button a new record is added to this table.

    Comment

    • Seth Schrock
      Recognized Expert Specialist
      • Dec 2010
      • 2965

      #3
      You would only have one subform and make that form's Default View property to be either Datasheet or Continuous. This will allow you to see all four records at the same time. The subform would use the query that I posted in post #6 as it's recordsource.

      Comment

      • Jeroen3131
        New Member
        • Oct 2014
        • 33

        #4
        Thanks Seth! I've got it working properly now! My next challenge is to see If I can isolate the ImageControl from the continuous subform. Currently, when I select a part, the image appears next to the combobox in an Image Control. Because it is a continous form, the layout is copied each time. But now I want to display the part images in a row with no spacing bewtween them.

        The idea I've came up with is to create a 2nd continuous subform with only an ImageControl in it. The MainForm contains a (hidden) textbox which's Rowsource is the 3rd column of the Parts Combobox. The result is that the ImagePath of the part is displayed in the textbox.

        Now I need to connect it to the ImageControl in the 2nd continuous form. The problem is, when I select a part in the 1st subform), the 2nd continuous form doesn't update and it doesn't move to a new record.

        I hope this is possible or else I have to redesign my form completely.

        Comment

        • Seth Schrock
          Recognized Expert Specialist
          • Dec 2010
          • 2965

          #5
          When you say "in a row with no spacing between them", do you mean horizontally or vertically. It is simple to get the vertical spacing to be nothing. Simply place the image control at the very top of the detail section of the form and then shrink the size up to the bottom of the image control. When viewed with data, all the images will be stacked perfectly one on top of the other.

          If you want them horizontally, I would say that it would probably be easiest to put them on the main form and then link them to the appropriate records in the subform via code.

          While it is possible to connect two subforms, it takes a lot of code and I wouldn't recommend it for this situation. I would personally do them as I described in the first paragraph. You will save yourself a lot of headache.

          Comment

          • Jeroen3131
            New Member
            • Oct 2014
            • 33

            #6
            I meant aligning them vertically.

            This is the current situation:

            Click image for larger version

Name:	Alignment Comboboxes and Image Controls.jpg
Views:	1
Size:	40.1 KB
ID:	5413895

            The continuous form within the red box has the same height as the ImageControl (both 0.58"). If I select a new part the Images apear directly underneath each other, which is exactly what I want. But the comboboxes need to be aligned closer to each other.

            Comment

            • Seth Schrock
              Recognized Expert Specialist
              • Dec 2010
              • 2965

              #7
              Personally, I would think that you would want the combo box to stay spaced as they are so that it is easy to visually see which image corresponds to which combo box. In this type of situation, I would normally put the combo box in the middle of the form, which is also the middle of the image.

              If you still want to have the combo boxes aligned closer to each other, I would recommend transferring the image controls to the parent form, make them unbound and have their names end with a 1, 2, 3 & 4 (for example Image1, Image2, etc). In your combo box's After_Update event, you will need to check which record number you have just edited and store this in a variable. You can then reference the appropriate image control like so:
              Code:
              Dim i As Integer  'stores edited record number
              i = Me.CurrentRecord
              
              Me.Parent.Controls("Image" & i).HyperlinkAddress = DLookup("ImagePath", "yourTable", "PartID = " & Me.ComboBox)
              I haven't worked with image controls much, so I don't remember off the top of my head which property it is that you use to set the image path so I chose the HyperlinkAddres s property. This assumes that you have linked images and not embedded images. You would then have to do something similar in the parent form's On_Current event so that it loads the proper images when you change records.

              Comment

              • Jeroen3131
                New Member
                • Oct 2014
                • 33

                #8
                You Sir, are my hero! Instead of using ".HyperlinkAddr ess"I used ".Picture" to set the controlsource for the ImageControl. By using the unbound ImageControls I can place them wherever I want on the main form. Thanks!

                Comment

                • Seth Schrock
                  Recognized Expert Specialist
                  • Dec 2010
                  • 2965

                  #9
                  Glad I could help. Good luck on the rest of your project.

                  Comment

                  Working...