Inserting a picture(OLE object) via command button

FIT

New member
Local time
Today, 18:39
Joined
Dec 18, 2010
Messages
1
Hello folks,

I'm new in Access and I could use some help. I have a table with an OLE object and some other information. I've created a form for inserting information in that table and I want to add a button to insert pictures from local hard drive.In other word I'm trying to make a button that will open a browse window.

Thank you in advance.
 
Don't. OLE stands for Objects as Large as Elephants. Leave the the image on the disc where they should be. If you need help to referentially access the images, just shout.

Simon
 
The whole process of putting an image on a screen should be automatic afterall the image is really an aide memoire. The image represents an asset and therefore has no intrinsic value unless you are an image library. Therefore by simply putting creating a StockID the image should appear. With over 30,000 works of art and of these over 16,000 have digital images you have to efficient. The point I would always make, once the image has been created it should present itself to the screen automatically.

If you want to be really clever using dbpix you are interrogate the image dimensions and image size, the later which is useful if these images are going up on the web.

With so many images and about half available it is also handy to know if a particular work of art has an image so that it is not a waste of time seeking an image if none is available.

Whilst this does not concern someone that has a small quantity of images, the use of vast array of images - efficiency is important.

Simon
 

Attachments

  • Image.gif
    Image.gif
    71.3 KB · Views: 878
The first thing you have to do is to consider how and you are going to store your images. These images must be standalone i.e. if you look at an image you must know what it relates to so i you a Stock reference or Exhibition Reference. The later we will forget about along with the categorisation of images by Artist. The path of the directory maybe superfluous as in most cases these should be in a fixed location, if is only when you have a pre-production environment for web site do you need to worry about managing image locations.

So lets get to basics. I actually use dbpix, it has worked since Access 1997. But I have tested and creating scripts using the standard ImageControl using Access 2007. There is I understand a change since Access 1997 with reports not dragging images form one record to another when an Image doesn't exist but i have left in these lines of code. These are all Functions no subs are used.

There is an assumption that the image exists before enter of data so that the image appears although you can add images later. The ImageFlag is only set when the Image is available. If the wrong image is used the image is deleted, once the record is accessed the ImageFlag will be reset. I think the Image Size property is only available with dbpix.

So here goes.

1) Create a query for the form or report and create the ImageFile [StockID] & ".jpg"

Optional:

2) On the Table create a Boolean Field called ImageFlag.
3) On the Table create an Integer Field called ImageHeight
4) On the Table create an Integer Field called ImageWidth

Add these to your query and create the control on your entry form. On the Imagecontrol needs to be visible, I generally hide the rest behind the image.

5) On the form drop a Image control onto the form call it what you like but always the same name I use ImageControl.

6) First Function GetImageDir one stop location of the Image:
Code:
Function GetImageDir() As String

    GetImageDir = "Drive:\whateverlocation\"

End Function
7) Create a function to Set the Image or Get the Image. The set updates the properties of the image. The Get only retrieves the image.

Code:
Function SetPicture()

Dim FullPath As String
Dim ImageW As Integer
Dim ImageH As Integer

    With CodeContextObject
        FullPath = GetImageDir & .[ImageFile]
        ImageW = CInt(.[ImageControl].ImageWidth / 15)
        ImageH = CInt(.[ImageControl].ImageHeight / 15)

        If Dir([FullPath]) = Empty And .[Image] = -1 Then
            .[Image] = 0
        ElseIf Dir([FullPath]) <> Empty Then
            If .[Image] = 0 Then
               .[Image] = -1
            End If
            If .[ImageWidth] <> ImageW Or .[ImageHeight] <> ImageH Then
                .[Image Width] = ImageW
                .[Image Height] = ImageH
'                .[Image Size] = .[ImageControl].ImageBytes
            End If
        End If
    End With
End Function
Or
Code:
Function GetPicture()

Dim FullPath As String

    With CodeContextObject
        FullPath = GetImageDir & .[ImageFile]

        If Dir([FullPath]) <> Empty Then
            .[ImageControl].Visible = True
            .[ImageControl].Picture = FullPath
        Else
            .[ImageControl].Visible = False
        End If
    End With
End Function
Then on the Forms Current Event SetPicture() or GetPicture()

Now handling subForms or lists, handy to have the ImageFlag. Create a Dialog Form much the same way as the Entry Form but you onlly need the ImageControl and ImageFile. On the Doubleclick Event =Originals_GetImage()
Code:
Function Originals_GetImage()

    With CodeContextObject
        If IsNumeric(.[StockID]) Then
            DoCmd.OpenForm "Originals Images Review", acNormal, "", "[StockID] = " & .[StockID], , acWindowNormal
        End If
    End With
End Function
On the Dialog Form Current Event =GetPicture()

The only point I'm making is that the management of images is not a database issue it is supplementary, it does makes a huge difference adding images but it should be painless. There are two other considerations, the first relates to back to Access 1997, any form with an image needs to be editable! The second, when you enter the StockID you need to SetImage or GetImage however you have to ensure that any required fields are completed first and you may need to wait until these are populated before getting the image.

On Reports create the ImageControl and Imagefile then

Detail Section on format =GetPicture()

I'm sure that I have missed something, I can't remember why there is a divide by 15 in SetPicture but I know the size of the images so it must have been required. As I said I use dbpix. I also have an dbpix function called ImageClear and that is triggered when entering multiple Stock records so that the ImageControl is cleared and doesn't drag through the previous image. I have not tested if this is required when using the Picture functions.

The last thing is whilst being colourful with forms, a white background nearly always works with images and also accentuates the Image. Sorry I renown for having a thing about grey or should I say silver.

Simon
 

Users who are viewing this thread

Back
Top Bottom