How to add image control

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • paukste
    New Member
    • Feb 2010
    • 5

    How to add image control

    Hi,

    I've created on a form an event to create a new report. I've almost done but can't solve one problem with newly created image control in the report.

    I have a source with image path but i couldn't find solution how to add this path info to the control.


    Below is the part of my code. I receive error on 15th line: "Run-time error'438': object doesn't support this property or method". Please give some advises.

    Code:
    Dim txtPhotoID As Access.Image
    
    Set rpt = CreateReport
    strReportName = rpt.Name
     
    title = "Report1"
    DoCmd.RunCommand acCmdDesignView
    
    rpt.RecordSource = "SELECT ImagePathlink FROM test1;"
    
    Set txtPhotoID = CreateReportControl(rpt.Name, acImage, _
             acGroupLevel2Header, , , 200, 200)
             txtPhotoID.SizeToFit
             txtPhotoID.Name = "CatgPhoto"
             rpt.Controls("CatgPhoto").ControlSource = "ImagePathlink"
  • ChrisPadgham
    New Member
    • Jan 2012
    • 11

    #2
    You can't bind an Image control to a datasource, you could try a bound Object control instead

    Comment

    • paukste
      New Member
      • Feb 2010
      • 5

      #3
      Thanks for your reply ChrisPadgham
      I'm not very advanced programmer. I'm not sure where to change and how to change my image to bound object :(
      I've tried only this

      rpt.Controls("C atgPhoto").Pict ure= "ImagePathl ink"

      But received message "can't open the file "ImagePathlink" . In this case I understand that "ImagePathl ink" is unserstood as the path of file. By the way I use Access 2007.

      Comment

      • Mihail
        Contributor
        • Apr 2011
        • 759

        #4
        I assume that ImagePathlink is a variable where you store the full path for your image. So the quotes are not necessary:
        Code:
        rpt.Controls("CatgPhoto").Picture= ImagePathlink
        This is one face of your problem. I think that will not solve your main problem: To show pic in the report.

        I post now for subscribe purpose but I'll try to solve your problem because is an interesting one.

        Comment

        • Mihail
          Contributor
          • Apr 2011
          • 759

          #5
          This work very well for me (see attachment) with no programming.
          Of course you must customize the addresses.

          Let me know if this is what you are looking for or I misunderstand your problem.
          Attached Files

          Comment

          • paukste
            New Member
            • Feb 2010
            • 5

            #6
            Thank for your help. Your example do not help me in this case. If I leave my code only to create image control without adding any control source (ImagePathlink) and then I go to the new created report and insert a control source ImagePathlink - I see pictures. The problem is I don't know how to create report and "tell" in the creation code to put control source.

            Comment

            • Mihail
              Contributor
              • Apr 2011
              • 759

              #7
              Thanks (again) to MMcCarthy : http://bytes.com/topic/access/insigh...port-using-vba

              I can develop this code:

              Code:
              Dim rpt As Report
                  Set rpt = CreateReport
                  With rpt
                      .Caption = "Report1"
                      .RecordSource = "SELECT ImagePathlink FROM test1;"
                  End With
                   
                  DoCmd.RunCommand acCmdDesignView
              
              Dim imgPhotoID As Access.Image
              
              Set imgPhotoID = CreateReportControl(rpt.Name, acImage, _
                       acDetail, , "ImagePathlink", 200, 200)
                       imgPhotoID.SizeToFit
              
              'This approach give me an error because -acGroupLevel2Header- not because "ImagePathlink"
              'Set imgPhotoID = CreateReportControl(rpt.Name, acImage, _
              '         acGroupLevel2Header, , "ImagePathlink", 200, 200)
              '         imgPhotoID.SizeToFit

              Comment

              • paukste
                New Member
                • Feb 2010
                • 5

                #8
                Thank you for your reply. I made changes according to your comments but when I look at the created report - no picture source is attached. I added my code.
                Attached Files

                Comment

                • Mihail
                  Contributor
                  • Apr 2011
                  • 759

                  #9
                  I can't open your database. I use 2007.

                  Sorry but I can't see any reason to don't work for you.
                  Now I attach the database. You must change the pics addresses according to your pictures paths.
                  Attached Files

                  Comment

                  • paukste
                    New Member
                    • Feb 2010
                    • 5

                    #10
                    Sorry, If you think that I want you to do my work, I put database to show that your code doesn't work in my case. In your example I changed the path of image and after I pressed button "Create report", I received white paper - no images. I can send you a printscreen to if you are interested in. But anyway. thank you for your assitants, I will try to solve this problem in other way. Thank you again.

                    Comment

                    • Mihail
                      Contributor
                      • Apr 2011
                      • 759

                      #11
                      Paukste !
                      Is how (and how I like) to learn myself: by analyze others code. It is why I provide you code and, finally, the database.
                      I can't understand why don't work for you.
                      Sorry for that.

                      If anyone else can make testes I'll thank he (she) very much.

                      Comment

                      Working...