Can two image subforms use the same module?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • CharT
    New Member
    • Sep 2011
    • 22

    Can two image subforms use the same module?

    I decided to try to add the picture feature to another form. So, I have two image subforms now, one for the kids pics and one for the adult pics. The kids one refers to the kids table, the adult to the adult table, etc.

    But ever since i tried to create the one for the adults form, my db crashes. it seems to have suffered some serious corruption, and I had to spend some time piecing it back together... i don't know if it is a coincidence or not.

    My question is can both of my image subforms use the same module? i am not at all experienced with code... i have found bits and pieces and used it, but i probably know enough to be really dangerous! Thanks again,
    Last edited by Niheel; Oct 1 '11, 06:37 PM. Reason: Spaced sentences to make readable. Moved: one question per thread.
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32634

    #2
    I suggest that really depends on your usage of the term subform.

    A form can be used as a subform. The same form design (with a single associated module) can be used as two separate subforms within another form. In that sense it is possible.

    If, on the other hand, you are referring to two separately defined forms which you want to act as subforms for a third, then in that sense it is not possible (as the module is directly associated with a form design).

    If the latter is what you're after then you still have some scope to define much of your code in a standard module and the rest in the two separate forms such that the two forms call the standard module code to do most of their work.

    Comment

    • CharT
      New Member
      • Sep 2011
      • 22

      #3
      Oh- i think i understand. would it help if i pasted the code? the subforms, called "imageA" and "imageC" (a is used in the adult main form and c is used in the child main form) are exactly the same, except for that the record source for a is the adult table and the record source for c is the child table.

      I had found some code that i used from the internet that looks up the file path in a text field of a table and displays that image. I combined it with the code i was given yesterday (here) to add the browse feature. I was pleasantly surprised that i was able to meld the two pieces together. Here it is:

      Code:
      Option Compare Database
      Option Explicit
      
      Public Function DisplayImage(ctlImageControl As Control, strImagePath As Variant) As String
      On Error GoTo Err_DisplayImage
      
      Dim strResult As String
      Dim strDatabasePath As String
      Dim intSlashLocation As Integer
      
      With ctlImageControl
          If IsNull(strImagePath) Then
              .Visible = False
              strResult = "No image name specified."
          Else
              If InStr(1, strImagePath, "\") = 0 Then
                  ' Path is relative
                  strDatabasePath = CurrentProject.FullName
                  intSlashLocation = InStrRev(strDatabasePath, "\", Len(strDatabasePath))
                  strDatabasePath = Left(strDatabasePath, intSlashLocation)
                  strImagePath = strDatabasePath & strImagePath
              End If
              .Visible = True
              .Picture = strImagePath
              strResult = "Image found and displayed."
          End If
      End With
          
      Exit_DisplayImage:
          DisplayImage = strResult
          Exit Function
      
      Err_DisplayImage:
          Select Case Err.Number
              Case 2220       ' Can't find the picture.
                  ctlImageControl.Visible = False
                  strResult = "Can't find image in the specified name."
                  Resume Exit_DisplayImage:
              Case Else       ' Some other error.
                  MsgBox Err.Number & " " & Err.Description
                  strResult = "An error occurred displaying image."
                  Resume Exit_DisplayImage:
          End Select
      End Function
      Last edited by Niheel; Oct 1 '11, 08:40 PM. Reason: please use code tags

      Comment

      • NeoPa
        Recognized Expert Moderator MVP
        • Oct 2006
        • 32634

        #4
        Not really :-S

        I wasn't sure what you were trying to say so I answered both possible interpretations of the question. It wouldn't hurt to make the question clearer, but that's probably redundant now as I've answered both possible interpretations anyway.

        I guess you haven't understood something of my answer(s). I suggest if you want help understanding that, you should explain where you're confused (It's hard to clear up confusion if you don't know where it is).

        Comment

        • CharT
          New Member
          • Sep 2011
          • 22

          #5
          I'm so sorry... i completely agree, its difficult to clear up confusion if you don't know where it is! I feel like a blind man trying to describe what i am seeing :)

          i think my use of the subforms fits your first scenario. (i think)... okay here i go again:

          I have a main form called "adult info" this main form has in the detail section the fields from the underlying table as well as the image subform that displays the adult's picture.

          I ALSO have a main form called "child info". This main form has lots of tabbed pages and lots of subforms... but, the in the detail section are the fields from the underlying child info table, and the (copy) of the image subform to display the child's image.

          Both the images subforms are exactly the same, other than the record source. One displays pictures of child from the file path stored in the child info table, and the other displays pictures of the adults from the file path in the adult info table.

          clear as mud?? :) (i am so very grateful for your help, as you can see i am not very good at this yet, but i aspire to be some day!)

          Comment

          • NeoPa
            Recognized Expert Moderator MVP
            • Oct 2006
            • 32634

            #6
            Subforms are complicated to explain, as general parlance describes both the form itself, and the control it's put in, as a subform. Whenever a subform is used on a main form there are three items that must exist :
            1. The main form itself. This will have a name and be found in your collection of forms in the database.
            2. A subform control on your main form. This is like a frame that the subform (#3 below) is displayed within. It is not a form as such.
            3. The sub form. This is also a form, has a name and is found in your collection of forms in the database. In fact, this can often be opened in its own right, though generally they are designed specifically for use within a subform control of another form.


            You've described, and given names to, two main forms that each have a subform. What is/are the name(s) of these subform form(s)? If the answer to both is the same name, then the module for both is the same. If you have an Adult Subform, and a separate Child Subform, then they are not.

            Comment

            • CharT
              New Member
              • Sep 2011
              • 22

              #7
              Thank you again for sticking with me on this! To answer your question, i have named my sub forms imagesa and imagesc. imagesa is on the main adults form, and imagesc is on the main children form.

              So- two answer that question, yes, they have different names- but when i look at me list of modules, i have only 1, the module that i created when i made the first subform, imagesc.

              when i copied imagesc and saved as imagesa so that i could add the picture feature to my adults form, it didn't make a module of its own, there is still only one. if i open both subforms (a and c) and look at the code in the code editor, they both have the exact same code.

              Do I need to copy and past the code into another module so they each use their own code?

              Thank you again,

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32634

                #8
                Can you confirm that when you talk about the objects ImagesA and ImagesC you are referring to form objects in the database and not control objects on forms. You don't seem to have picked up on the need for clarity of explanation made necessary by the ambiguity of the term in use. I know what I think you mean, but I'd rather deal with certainty at this stage, after having raised the point already in an earlier post.

                Comment

                • CharT
                  New Member
                  • Sep 2011
                  • 22

                  #9
                  i'm sorry, they are form objects. not control objects on forms.

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32634

                    #10
                    It's possible then, if your options are set that way, to have form and report objects without associated modules.

                    My first question for you to consider at this point would be - Is it necessary to have two separate forms for your images? If you can manage to use the same form as the subform for both main forms then that would make the most sense. If not, then ensure each has an associated module (For the one without, select a control and set one of the events of that control to "[Event Procedure]" from the Properties pane).

                    Once they both have modules available you can do what you will with them. To be honest I'm struggling to know what you're actually asking for. I hope I've answered the question, but if not just let me know, and what the question actually is, and I'll do what I can to help.

                    Comment

                    • CharT
                      New Member
                      • Sep 2011
                      • 22

                      #11
                      Yes, thank you that answers my question. I will implement your suggestions.

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32634

                        #12
                        Go for it - and good luck :-)

                        Comment

                        Working...