Embed Image within DataBase

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • OldBirdman
    Contributor
    • Mar 2007
    • 675

    Embed Image within DataBase

    I have an image control on a form. I want to embed an image within the database for this control. How do I do that?

    I started with a picture located in my computer at C:\Desktop\PicN ame and linked to that picture. I changed the PictureType to Embedded, but cannot remove the link to the picture without removing the picture from the control. Unless the link is valid, I cannot open the form. However, the correct picture is displayed in Design View even with a bad link.

    Picture is .jpg (but I could change that)
    Access 2003
    Windows XP and/or Windows Vista - both computers up-to-date with sp's, etc.
  • slenish
    Contributor
    • Feb 2010
    • 283

    #2
    Hello OldBirdman,

    When using Images as long as you have Embedded selected the program will save a copy of the image to it. For some reason it still keeps the address which does not really matter because it does not link back to it for any reason so you dont really need to remove it. If its an address you dont want people to really see should they get to the backend I would just create a dummy folder move your images to that first then set up the Embedded image.

    Hope that helps :D

    Also make sure to try and scale down your image as much as possible or else you will see your DB size grow quickly if you are using a lot of really high rez images. One i was building went from 0 - 60mb and I did not have any info in it yet :D

    Comment

    • OldBirdman
      Contributor
      • Mar 2007
      • 675

      #3
      Thanks for replying.

      I want to display 1 of 4 icons(images) to be determined within VBA code, and I want Access to store these images within the database.
      I created 4 Image Controls, and embedded the icons within them using complete file names. I set PictureType = Embedded and Visible = No. To show an icon, I use:
      Code:
      imgShowLevel.Picture = imgLevel2.Picture
      This works as long as the path to imgLevel2 is valid. If the path is not valid (the icon is no longer in my files as it is embedded within Access), the statement fails with "Run-time error '2220': Microsoft Office Access can't open the file 'C:\Desktop\Pic Name2.jpg'."
      The answer then is to set 1 of the 4 hidden Image Controls to .Visible = True and not try to move the image to a 5th control.
      OK, problem solved, but why can't I assign the property of one control to another?

      Comment

      • slenish
        Contributor
        • Feb 2010
        • 283

        #4
        Hi OldBirdman,
        Sorry took me a little while to write you back. I think I might be able to help you. A couple questions for you. The icon images do you only have one embedded image that you are trying to have change to another one? Or do ysou have many images and you are just trying to make certain ones visible? I would put all of your icon images on your form. Set them as visible = false then create a control that will make them visible as you click on the control. If you can attach a sample of what you are trying to do I can make adjustments for you :D I have a db where I built a really nice icon feature so I have sone experience with it.

        If you have already fixed the problem then disregard.

        Slen :)

        Comment

        • OldBirdman
          Contributor
          • Mar 2007
          • 675

          #5
          No problems Slen. What with weekends, holidays, & time zones, forums aren't the fastest way to communicate.
          I want to learn how to use a Form as a Function, returning a value to the calling statement. I also want to use MsgBox with a CheckBox to "...not show this message again". This would allow me to use errors to teach use of a project with many errors caught, and as the operator learns, the warnings can be suppressed. So that is what I am trying to do.
          To make my MsgBox similar to the familar M$ MsgBox, I want to add those icons that M$ uses, the ?, !, i, X. I can't find them in my computer, so I created them on the Desktop and called them Icon1.jpg, Icon2.jpg, Icon3.jpg, and Icon4.jpg. There could be more in the future. They are about 2K bytes each, no big deal. Then I created imgLevel1 and set .Picture to C:\Desktop\Icon 1.jpg and .PictureType to Embedded. Same for imgLevel2, imgLevel3, and imgLevel4.
          Code should be simple:
          Code:
          Select Case iLevel
          Case 1
             imgShowLevel.Picture = imgLevel1.Picture
          Case 2
             imgShowLevel.Picture = imgLevel2.Picture
          ...
          End Select
          If the images still reside on the Desktop, the code works. But because I should no longer need these, I removed them from the Desktop, and the program errors, "Run-time error '2220': Microsoft Office Access can't open the file 'C:\Desktop\Ico n1.jpg'."
          There are work-a-rounds, sure. What comes to mind is to stack the permanent images in design view, and display the correct image with the .Visible Property at Run Time. If iLevel is 2, for example (see code above), then Case 2 would be:
          Code:
          imgLevel2.Visible = True
          If this is the way to go, so be it. Either the controls have to be stacked, and therefore more difficult to work with in design view, or the form must stack them when Opened at Run Time.
          Thank you for your attention !

          Comment

          • slenish
            Contributor
            • Feb 2010
            • 283

            #6
            Hi OldBirdman,

            Yea the holidays have made things a little hectic plus I started coming down with a cold so that hasn't made things any better :(

            I would say the best way to do this would be to put your images permanently hidden in design view. One advantage to this is it helps keep things quick when the code goes to reference the image. It its kind of a pain to work with when they are stacked but saves you other pain down the road. Another thing you could do is use the move function when the image is visible this way you dont have to stack them you could have them layed out in the detail part of the form then just set the image1.move to where you want it to go once its becomes visible.

            Sounds pretty cool what you are working on. I'll have to try and see if I can make a dummy example and you can take a look at it and we can figure out how to make it work the way you want it to :D

            Comment

            • slenish
              Contributor
              • Feb 2010
              • 283

              #7
              Hi OldBirdman,

              Ok I put together a little something. Im not quite sure if this is the idea you were having and its not fully working as of yet, but i whipped together something for you to kind of get a better idea of what you are trying to do. There is a msgbox that pops up if you are wrong but the dont display check box does not work yet. I dont want to build to much if Im way off base. But i built in some images for you and have them pop up if you do something right and a msgbox pop up if you do something wrong. I hope this helps you some! :D
              Attached Files

              Comment

              • OldBirdman
                Contributor
                • Mar 2007
                • 675

                #8
                Slen - hope you're feeling better w/New Year :)

                Thanks for the sample. For the image handling, logically similar to mine, as I would expect. The images are obviously embedded, because they were visible when I ran your Access program "Image Test".
                I added the line of code:
                Image0.Picture = Image2.Picture
                in the Select Case ... Case 1 code. This line of code cannot be executed. The same error occurs as detailed in my post #3, except that the file is "C:\Documen ts and Settings \C;\Documents and Settings\slenis h\Desktop\..... " Imagine that. Access can't find your desktop from my computer. Oh well (sigh).

                But seriously, if Image2.Picture is a valid property, containing an embedded image at run-time, why can't it be assigned to another control with the .Picture property?

                I tried
                Image0 = Image2
                figuring I could then assign .Left and .Top to put it back where it belongs. Doesn't work. "Run-time error '438': Object doesn't support this property or method"

                For now, I will use the simple method of creating enough controls and making them .Visible = True as necessary. I won't try to put the same image in each corner of a form, or something equally complex.

                I'm attaching my progress so far. Still needs some work with the form width & height, and centering text, but for the goals stated in Post #5, I'm satisfied.
                Attached Files

                Comment

                • slenish
                  Contributor
                  • Feb 2010
                  • 283

                  #9
                  Hi OldBirdman,

                  Hope you didnt think i forgot about you! Well im staring to feel better now and got a chance to look over your file. Have to say I like the way its looking very nice!

                  Well I rebuilt your images for you a little bit and tried something different that you may like so you dont have to stack them all in one place. I was having some trouble getting them to pop up so what I did was comment out some of your code and built the function in to your buttons on the pop up message (hope you dont mind). All you have to do is press the different buttons and each image will appear. If you look on the back you will see I moved all of your images below the buttons so you can see them but when they open they move to where you want them.

                  Also I was researching more in to embeding images and found out something about setting images as OLE objects. It sounds little more complex and may not be worth doing if you only have a few icon images but could be something to look in to down the road. I have to play around with it myself more to see how to actually make it work.

                  Also if you want any other help with this project let me know looks pretty cool wouldnt mind putting my own skills to the test.

                  anyway let me know what you think

                  later

                  Slen :D

                  link: http://office.microsoft.com/en-us/ac...005280225.aspx
                  Attached Files

                  Comment

                  • slenish
                    Contributor
                    • Feb 2010
                    • 283

                    #10
                    I made some adjustments

                    :D
                    Attached Files

                    Comment

                    Working...