Open Image Based on Subform Record Selected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ablevins
    New Member
    • Jan 2013
    • 5

    Open Image Based on Subform Record Selected

    I have a access searchable form that displays results in a subform.

    One of the fields in the subform results is ImagePath.

    I want to be able to select a record from the results, then click a button that would open a pdf for that specific record using ImagePath.
  • TheSmileyCoder
    Recognized Expert Moderator Top Contributor
    • Dec 2009
    • 2322

    #2
    You could use a button on the record with code like the following:
    Code:
    Private Sub btn_Open_Click
      Application.FollowHyperLink Me.ImagePath
    End Sub

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32653

      #3
      The fact that this is a subform doesn't change anything. The same approach could be used on any form.

      You could also trigger the code on either the change of record, or double-clicking on the control with the image path in it. Both of these would save the extra space for the button, which is especially a problem if the form is in Continuous Form mode.

      Comment

      • TheSmileyCoder
        Recognized Expert Moderator Top Contributor
        • Dec 2009
        • 2322

        #4
        Curios how would you accomplish this:
        You could also trigger the code on either the change of record
        I imagine using the subforms current event, but that would fire in alot of unwanted cases, which you would have to code for.

        If the imagepath is a visible control, another option (as per NeoPa's suggestion) could be to change the controls properties to format it as a hyperlink, and then code the opening to occur on DoubleClick for example.

        Comment

        • ablevins
          New Member
          • Jan 2013
          • 5

          #5
          Thanks for your replies guys.

          TheSmileyCoder I tried what you suggested and I get a
          • Compile error: Method or data member not found.

          So I tried changing Me.ImagePath to Me!ImagePath and then got the below error.
          • Run-time error '2465' Microsoft Office Access Can't find field 'ImagePath' referred to in your expression.

          Any idea?

          Comment

          • TheSmileyCoder
            Recognized Expert Moderator Top Contributor
            • Dec 2009
            • 2322

            #6
            In your first post you stated that the field in the supreport was called ImagePath.
            If access can't find ImagePath its likely because you made a mistake in telling us the name of the field/control containing the path to your file.

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32653

              #7
              Originally posted by Smiley
              Smiley:
              If access can't find ImagePath its likely because you made a mistake in telling us the name of the field/control containing the path to your file.
              Almost certainly. I can think of no alternative explanation.

              Comment

              • ablevins
                New Member
                • Jan 2013
                • 5

                #8
                I am completely new and I have no idea what I must be missing to get this to work.

                I don't know if you have time to look at my test db for me.

                If not, I'll still play around to get it to work.

                Thanks
                Attached Files

                Comment

                • NeoPa
                  Recognized Expert Moderator MVP
                  • Oct 2006
                  • 32653

                  #9
                  Originally posted by Ablevins
                  Ablevins:
                  I am completely new and I have no idea what I must be missing to get this to work.
                  Have you considered the idea already put forward, that the control name is incorrect?

                  Going through someone's project is something which takes a lot more effort than dealing with intelligent textual responses in the thread. I won't say none of us ever does it, but I certainly wouldn't consider it while the thread still has outstanding ideas proposed that have apparently not been considered yet. If we get to that stage then we will generally inform you and give some instructions on how you would go about preparing for that properly.

                  Comment

                  • TheSmileyCoder
                    Recognized Expert Moderator Top Contributor
                    • Dec 2009
                    • 2322

                    #10
                    You placed the button in the main unbound form. Whichever "item" click you choose to active the record, it will be easiest if it is on the subform itself. As the item is clicked a number of things happen. The subform receives focus, then the record under the mouse receives focus, then the button receives focus, and then the click event is fired. As you can see part of this process is that the record is selected. How else shall access know which records imagepath it is you want to open?

                    So make sure to use a click event that is on the subforms DETAIL area. It could be the click of any of the textboxes, OR a button. Then within that click event use the before mentioned Application.Fol lowhyperlink

                    Comment

                    • ablevins
                      New Member
                      • Jan 2013
                      • 5

                      #11
                      Ohhhh, I didn't even think about that. I will give it a try again.

                      Thanks

                      Comment

                      • ablevins
                        New Member
                        • Jan 2013
                        • 5

                        #12
                        TheSmileyCoder,

                        I did what you suggested and it kind of works.

                        When I click the button, it opens the pdf then quickly closes it. And this all happens fast enough that I can't even see what the pdf is.

                        Any ideas why this would happen?

                        Comment

                        • TheSmileyCoder
                          Recognized Expert Moderator Top Contributor
                          • Dec 2009
                          • 2322

                          #13
                          Sorry, no idea at all. I presume if you open the same pdf manually there is nothing wrong?

                          Comment

                          • zmbd
                            Recognized Expert Moderator Expert
                            • Mar 2012
                            • 5501

                            #14
                            Please read the following:Before Posting (VBA or SQL) Code
                            Please double check that you have done the first part of the article linked to.
                            Make sure that you can compile your code without any errors. One thing to note, the compiler stops at the FIRST error encountered. You must REPEAT the compile step.

                            Once you've done this, please post the code behind your click event for opening the PDF.

                            Comment

                            • NeoPa
                              Recognized Expert Moderator MVP
                              • Oct 2006
                              • 32653

                              #15
                              Originally posted by Ablevins
                              Ablevins:
                              When I click the button, it opens the pdf then quickly closes it.
                              This sort of behaviour is normally seen when something happens related to an object variable that is stored locally, then goes out of scope and gets cleared down. I can't think what might fit that pattern when dealing with a hyperlink, but we'd need to see the code to be sure. Please follow Z's instructions carefully before posting the full code from the procedure in question.

                              Comment

                              Working...