Need help with jpg.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • robertoathome
    New Member
    • Mar 2007
    • 20

    Need help with jpg.

    We use Access 2002.
    I have a table that contains a column with hiperlinks to jpgs stored on a disk on the network.
    I created a form that shows all the fields in the table including the pictures. If I use and OLE object with bmp images all is good. The problem is that I can't use bmp. If I try to display a jpg on an image box/ bound or unbound object box / text box or.... nothing comes up. I put a bmp on the first 2 records and they work; as move to the 3rd the other records no jpg is displayed. I'm not good with coding but I read somewhere that I can create a macro or code that can be a workaround.
    Can any1 help me? It's really getting to me :) I've been reading for days on the syntax to use in coding but my company doesn't want me to spend all this time "training myself"
    Can I use a macro or do I need to write a code?
    If the workaround needs a button to open the pic in the form, ..not the ideal but...so be it.

    Table name= table1
    Form name= ViewRecord
    field name= Photo

    Thanks!
  • Denburt
    Recognized Expert Top Contributor
    • Mar 2007
    • 1356

    #2
    O.K. it's bee a while since I fooled with linked pics but you should be able to use the on Current event of the form.

    Code:
    Private Sub Form_Current()
    Rename the folowing Me!myLink with the field that hold the links
    If Not IsNull(Me!MyLink) And Len(Me!MyLink) > 0 Then
    'Me!Image0 should be the image placeholder also replace the myLink as stated above
    Me!Image0.Picture = Me!MyLink
    End If
    End Sub
    This should get you close any issues let me know.

    Comment

    • robertoathome
      New Member
      • Mar 2007
      • 20

      #3
      OK, something is working but not all.

      1) I'm assuming I need to use the first type of image holder, not the unbound or bound OLE object.
      2) when I run the code I get an error that says"

      "run-time error '2220':
      Microsoft access can't open the file 'T:\SHARED FILES\Administr ation\Masters and Molds Photos\040F-6F222032-TL.JPG#T:\SHARE D FILES\Administr ation\Masters and Molds Photos\040F-6F222032-TL.JPG#.

      Basically it dubles the link I have in the table1 and adds a ' # ' after it.
      If I go to debud I get the following highlighted
      ' Image42.Picture = Photo'

      Here's the code I used:

      Private Sub Form_Current()
      If Not IsNull(Photo) And Len(Photo) > 0 Then
      Image42.Picture = Photo
      End If
      End Sub

      THANKS!


      Originally posted by Denburt
      O.K. it's bee a while since I fooled with linked pics but you should be able to use the on Current event of the form.

      Code:
      Private Sub Form_Current()
      Rename the folowing Me!myLink with the field that hold the links
      If Not IsNull(Me!MyLink) And Len(Me!MyLink) > 0 Then
      'Me!Image0 should be the image placeholder also replace the myLink as stated above
      Me!Image0.Picture = Me!MyLink
      End If
      End Sub
      This should get you close any issues let me know.

      Comment

      • robertoathome
        New Member
        • Mar 2007
        • 20

        #4
        In doubt of the syntax I aslo added the " Me!" :

        Private Sub Form_Current()
        If Not IsNull(Me!Photo ) And Len(Me!Photo) > 0 Then
        Me!Image42.Pict ure = Me!Photo
        End If
        End Sub

        "Photo" is the column in my table that holds the links to the pictures.

        Comment

        • Denburt
          Recognized Expert Top Contributor
          • Mar 2007
          • 1356

          #5
          ??? How large are your pics?

          I tried tried it with some windows sample pics and hadd no problem what so ever. Did you change any of the properties on the control? I simply placed the control added a dummy pic as it asked for 1 but when it opens it opens whith my first pic from the bd.
          I tried it using the field photo and didn't have an issue but I don't like using any 1 word for a fieldname since you never know when or if MS has designated it as a property, method, or function.

          MyPhoto as Text Field
          C:\Documents and Settings\All Users\Documents \My Pictures\Sample Pictures\Blue Hills.jpg
          C:\Documents and Settings\All Users\Documents \My Pictures\Sample Pictures\Sunset .jpg
          C:\Documents and Settings\All Users\Documents \My Pictures\Sample Pictures\Water Lilies.jpg
          C:\Documents and Settings\All Users\Documents \My Pictures\Sample Pictures\Winter .jpg

          Each one in a separate record and it went smoothly.

          The following site is using a class module for his example and maybe this might be a resolution for you. At this point i don't know what else I can offer.

          Image Sample DB

          Comment

          • Denburt
            Recognized Expert Top Contributor
            • Mar 2007
            • 1356

            #6
            UGH Just reread your Post you are using Hyoperlink as a field to hold your pics that explains it!

            If you have to use a hyperlink field then you will need to parse it.

            In your current code before you set the picture.

            Ytou will need to use something to the effect of:
            Code:
            instr(Me!'Photo,"#")
            if instr>0 then
            strPhoto = left(me!Photo,instr)
            End if
            A Hyperlink field stores the link and the text you want displayed. If you don't enter text to display it will display the link twice using # as a separator, as you posted.

            Comment

            • robertoathome
              New Member
              • Mar 2007
              • 20

              #7
              BETTER news !
              I don't "have to" use hyperlinks but it is easier than changing all my database to text.
              With simple text the code in the "Photo" field actually now works! I had to change the allowable number of characterd in the field since the links are long.

              I tried to add your second piece of code u gaver me to 'parse the link' but I get a syntax error no matter where I place the code. Below is where I 'think' you wanted me to insert it.

              Private Sub Form_Current()
              instr(Me!'Photo ,"#")
              if instr>0 then
              strPhoto = left(Me!Photo,i nstr)
              End If
              If Not IsNull(Me!Photo ) And Len(Me!Photo) > 0 Then
              Me!Image42.Pict ure = Me!Photo
              End If
              End Sub

              The debugger stops at the very first line and makes the new code part red.

              I appreciate your help!

              Comment

              • robertoathome
                New Member
                • Mar 2007
                • 20

                #8
                BETTER news !
                I don't "have to" use hyperlinks but it is easier than changing all my database to text.
                With simple text the code in the "Photo" field actually now works! I had to change the allowable number of characterd in the field since the links are long.

                I tried to add your second piece of code u gaver me to 'parse the link' but I get a syntax error no matter where I place the code. Below is where I 'think' you wanted me to insert it.

                Private Sub Form_Current()
                instr(Me!'Photo ,"#")
                if instr>0 then
                strPhoto = left(Me!Photo,i nstr)
                End If
                If Not IsNull(Me!Photo ) And Len(Me!Photo) > 0 Then
                Me!Image42.Pict ure = Me!Photo
                End If
                End Sub

                The debugger stops at the very first line and makes the new code part red.

                I appreciate your help!

                Originally posted by Denburt
                UGH Just reread your Post you are using Hyoperlink as a field to hold your pics that explains it!

                If you have to use a hyperlink field then you will need to parse it.

                In your current code before you set the picture.

                Ytou will need to use something to the effect of:
                Code:
                instr(Me!'Photo,"#")
                if instr>0 then
                strPhoto = left(me!Photo,instr)
                End if
                A Hyperlink field stores the link and the text you want displayed. If you don't enter text to display it will display the link twice using # as a separator, as you posted.

                Comment

                • Denburt
                  Recognized Expert Top Contributor
                  • Mar 2007
                  • 1356

                  #9
                  Glad you got it working :) sorry for my sloppy coding I just looked at it and it WAS bad. My appologies it should have looked like the following. I did test this one btw

                  Code:
                  Private Sub Form_Current()
                  'Always declare your variables
                  Dim inInt as integer
                  Dim strPhoto as string
                  inInt = InStr(Me!Photo, "#")
                  If inInt > 0 Then
                  Debug.Print Left("MyPhoto.html#photo.html", inInt - 1)
                  strPhoto = Left(Me!Photo, inInt)
                  End If
                  If Not IsNull(Me!Photo) And Len(Me!Photo) > 0 Then
                  Me!Image42.Picture = Me!Photo
                  End If
                  End Sub

                  Comment

                  • robertoathome
                    New Member
                    • Mar 2007
                    • 20

                    #10
                    I'm sorry to bug you one more time but now at least the problem seems almost solved.
                    I still get this error:
                    Run-tme error '2220'
                    Microsoft Access can't open the file '#C:\Documents and Settings\ELIAS\ Desktop\new\200 2\040F-6F182424.jpg#'

                    The debug highlights:
                    Me!Image42.Pict ure = Me!Photo

                    It looks like the '#' still gets added in the string. :(

                    I don't get it. I tried links that work with using just text so they are working. If I click them I can open the pics. I also used local pics, in the same folder at the database. This is what I have as the first 2 links:
                    C:\Documents and Settings\ELIAS\ Desktop\new\200 2\040F-6F182424.jpg
                    or
                    T:\SHARED FILES\Administr ation\Masters and Molds Photos\040F-6F18D24.JPG

                    The pics are only 200kb

                    I tried to put nothing in the "text to display" and no changes.
                    Thanks!!

                    =============== ==

                    Originally posted by Denburt
                    Glad you got it working :) sorry for my sloppy coding I just looked at it and it WAS bad. My appologies it should have looked like the following. I did test this one btw

                    Code:
                    Private Sub Form_Current()
                    'Always declare your variables
                    Dim inInt as integer
                    Dim strPhoto as string
                    inInt = InStr(Me!Photo, "#")
                    If inInt > 0 Then
                    Debug.Print Left("MyPhoto.html#photo.html", inInt - 1)
                    strPhoto = Left(Me!Photo, inInt)
                    End If
                    If Not IsNull(Me!Photo) And Len(Me!Photo) > 0 Then
                    Me!Image42.Picture = Me!Photo
                    End If
                    End Sub

                    Comment

                    • robertoathome
                      New Member
                      • Mar 2007
                      • 20

                      #11
                      Now as my brain turns ( this thing is obsessing me! ) I thought maybe importing the data put something funky in the field so I created a fresh columb in the table an put a fresh link.
                      Same problem which alternates with the link getting doubled.

                      The I put an "NA" in the 'text to display' field of the hyperlink and the error now is:

                      Run-tme error '2220'
                      Microsoft Access can't open the file 'NA#C:\Documents and Settings\ELIAS\ Desktop\new\200 2\040F-6F182424.jpg#'

                      Comment

                      • Denburt
                        Recognized Expert Top Contributor
                        • Mar 2007
                        • 1356

                        #12
                        O.K.
                        Code:
                        Debug.Print Left("MyPhoto.html#photo.html", inInt - 1)
                        strPhoto = Left(Me!Photo, inInt-1)
                        The debug.print statement in the VBA window will show you the results in the immediate window. In the VBA window go to the View Menu then click on immediate window (Ctrl G) you should see it show up.

                        I had that in while testing and if you look closely the debug statement had a minus 1 after the variable inInt that will remove the trailing # symbol. The above should resolve your issue. Good luck let me know how it works.

                        Comment

                        • robertoathome
                          New Member
                          • Mar 2007
                          • 20

                          #13
                          Well, I swear, if some1 asked me now to rate my intelligence I'd be very crititcal....an d confused :)

                          I'm still getting the same error.

                          I opened the 'immediate window' and the first time it showed a few lines with " "myphoto" or similar.
                          Now nothing, only return lines, empty.
                          I added the - before the 1 :

                          Code:
                          Private Sub Form_Current()
                          'Always declare your variables
                          Dim inInt As Integer
                          Dim strPhoto As String
                          inInt = InStr(Me!Photo, "#")
                          If inInt > 0 Then
                          
                          Debug.Print Left("MyPhoto.html#photo.html", inInt - 1)
                          strPhoto = Left(Me!Photo, inInt - 1)
                          
                          End If
                          If Not IsNull(Me!Photo) And Len(Me!Photo) > 0 Then
                          Me!Image42.Picture = Me!Photo
                          End If
                          End Sub

                          Also noticed that you have

                          Debug.Print Left("MyPhoto.h tml#photo.html" , inInt - 1)

                          Shouldn't it be Me!Photo and capital P after # ?

                          How about the space, on the first one you have
                          inInt - 1

                          on the following line
                          inInt-1

                          I just I'm just reaching :)

                          If I'm understanding correctly the code is only trying ot take the initial #. There is one also at the end of the hyperlink.

                          The time you're taking is immensly appreciated.

                          Comment

                          • Denburt
                            Recognized Expert Top Contributor
                            • Mar 2007
                            • 1356

                            #14
                            The code I supplied will pick up the first part of the link, I take it that this would be the text to display so if that isn't the link my bad. Slight adjustment needs to be made.
                            The I put an "NA" in the 'text to display' field of the hyperlink and the error now is:
                            Run-tme error '2220'
                            Microsoft Access can't open the file 'NA#C:\Document s and Settings\ELIAS\ Desktop\new\200 2\040F-6F182424.jpg#'
                            Also my debug statement was just parsing a string I wasn't trying to tie it into your form or anything.
                            Debug.Print Left("MyPhoto.h tml#photo.html" , inInt - 1)

                            Code:
                            Dim inInt As Integer
                            Dim strPhoto As String
                            inInt = InStr(Me!Photo, "#")
                            If inInt > 0 Then
                                strPhoto = Mid(Me!Photo, inInt + 1, Len(Me!Photo) - inInt - 1)
                            End If
                            If Not IsNull(Me!Photo) And Len(Me!Photo) > 0 Then
                                Me!Image42.Picture = Me!Photo
                            End If

                            Comment

                            • robertoathome
                              New Member
                              • Mar 2007
                              • 20

                              #15
                              Here I am again.
                              Same problem.

                              The # is still there. The code is reading from the "text to display" which is ok to me.

                              When I insert a new link in the table the code reads it twice and puts it twice in the len part. If I point the mouse on the last Len statement the tooltip shows a count of 142 instead of 71. Plus is still puts the ' # ' . This only happens when I insert a new link in my table.

                              What I also don't understand is why if I look at
                              Code:
                              strPhoto = Mid(Me!Photo, inInt + 1, Len(Me!Photo) - inInt - 1)
                              and point the mouse on strPhoto, it shows the correct link without the # but if I scroll down to the last line of code
                              Code:
                              Me!Image42.Picture = Me!Photo
                              and point the mouse to Me!Photo it shows the link with the #.


                              Aren't you happy to have decided to help me? :)

                              Current code:
                              Code:
                              Private Sub Form_Current()
                              Dim inInt As Integer
                              Dim strPhoto As String
                              inInt = InStr(Me!Photo, "#")
                              If inInt > 0 Then
                                  strPhoto = Mid(Me!Photo, inInt + 1, Len(Me!Photo) - inInt - 1)
                              End If
                              If Not IsNull(Me!Photo) And Len(Me!Photo) > 0 Then
                                  Me!Image42.Picture = Me!Photo
                              End If
                              End Sub

                              Comment

                              Working...