Page 1 of 2 12 LastLast
Results 1 to 15 of 18
  1. #1
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Unanswered: Insert object from file

    Hi.
    I would like to import a JPEG file into a OLE object of a table using VB code. Can anyone help me wit this pice of code ?

    Thanks

  2. #2
    Join Date
    Mar 2004
    Location
    Slovenia
    Posts
    56

    Converter

    Is it possible that you convert pictures with some outside program and then insert them as bmp...

    A friend of my did this in navison...
    Back to the basics...

  3. #3
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Talking Good enough for Fred

    .... did you have any code examples ?

    sincerely
    Vestigo

  4. #4
    Join Date
    Mar 2004
    Location
    Slovenia
    Posts
    56
    sorry, not yet, because he didn't give me the complete instalation and I couldn't access his database....

    But Navison uses it own programing language...so I don't know if the code helped you...
    Back to the basics...

  5. #5
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Angry So, back to basic.

    Is my objective clear enoug ?
    I want to insert a OLE object into a OLE field in a table using VB code.
    (Using menu it would be: “insert object” - “create from file”)

    sincerely
    Vestigo

  6. #6
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Vestigo,

    Your objective is clear enough. Unless they changed it in the newest version of Access, there is not easy way through code to do that. You can use a “paste action” on an OLE object to get text from the clipboard, but getting an image is much more complicated – which is probably why you have few responses.

    I can suggest several options, which will either require some funds or some research.

    Option 1: Get an image from the clipboard into your file

    You can physically click on the OLE field and use then click any of the paste functions (Ctrl-V, Right-Click, Paste Button)

    To use the clipboard through code, however, can be a complicated venture in VBA for anything more heavier than text. The OLE Paste method only works for text – to get the image, you’ll have to manipulate the image’s location in memory, convert it to a bitmap format and then embed the data in Access. You will have to search the web for information on using the clipboard and will need a 3rd party tool to convert the JPG to a BMP, and most of the code you find will be written in C++.

    In addition to the complicated code, the OLE conversion engine for Access is terribly inefficient. To see how bad it is, create a table with an OLE field. Create a form with that field and add a few pictures by using the paste button. Watch how the size of the mdb grows much faster than the size of the images you are pasting.

    Option 2: Purchase a 3rd party “plug in” that does the task for you

    There are a number of them out there, and it comes down to a factor of “time versus money”. Either you spend the time researching, developing and debugging, or you spend the money on buying it ready to go.

    I personally chose to not take either option (which is why I have no code to offer you).

    I developed a tool that provides a button to add an image to the db using Access’s File Open dialog to select the file (in any standard image format). My module stores the image data directly in a table and recreates the file in the temp directory for viewing in an image control and printing. My module also provides the user with the ability to export the image from the db back to a file, using Access’s Save As dialog. This method produces an exactly 1 for 1 size ratio when bringing an image in and I am able to impose a file size restriction (which you can’t do with the clipboard).

    My method also has the same 2 options (Time vs. Money). If you choose Option 1, start with “Storing binary data” in your search for how to do it.

    Good luck!
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

  7. #7
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Red face

    Hi Todd.

    Thanks for your informative information. (Now I understand why my database grows for ‘no reason’) :-/

    The tool yo developed yourself, is the code by chance available ?
    It seems to describe what I’m actually are looking for.

    Sincerely
    Vestigo

  8. #8
    Join Date
    Nov 2003
    Location
    Sussex, England
    Posts
    404

    Jpeg into Database

    Just a word of advice. Don't do it.

    Not only will your database grow quickly if you put any images into the tables, but it wil lbecome unstable and more liable to corrupt. We used to use that technique a few years ago and gave up when the database corrupted and couldn't be recovered.

    I would seriously suggest that you put a link in your table to where the picture sits on the disk. That way you won't get the performance drag from having the image sitting in your database, you won't neet to use OLE (the image object will do quite well).

    I did have code for putting the image into the file from the form (it grabbed the image in put it on the form and from there into the table) but frankly I'm not prepared to dig it up for what think is a futile, and unwise, approach.

  9. #9
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Cool

    Hmmmm.
    I intend to use this for one single picture only, namely the logo to the company buing my application. Do you still think it’s an bad idea to import the picture into my application ?
    For all othe pictures used in my application I’m using linked objects.

    thanks a lot for your advice.

    sincerely
    Vestigo

    PS! I just found an example that perfectly well import a image to a OLE field in a table.
    But now, I’m not sure if I want to use it at all :-/

  10. #10
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239
    For the record, the example was found at http://accdevel.tripod.com

  11. #11
    Join Date
    Mar 2004
    Location
    Slovenia
    Posts
    56

    Stability

    just a question about stability!

    I am developing a database that have some tables with OLE objects. All OLE object are Excel file....

    Is here still a major posibility that database become unstable...

    thx!
    Back to the basics...

  12. #12
    Join Date
    Nov 2003
    Location
    Sussex, England
    Posts
    404

    Jpeg into Database

    "I intend to use this for one single picture only, namely the logo to the company buing my application. Do you still think it’s an bad idea to import the picture into my application ?

    For all othe pictures used in my application I’m using linked objects."

    No that should be fine, but I would use the image control rather than the OLE control. Putting the image in through code would simply be a case of setting the image box properties, probably in the Form OnLoad event.

  13. #13
    Join Date
    Jan 2004
    Location
    Islamabad, Pakistan
    Posts
    97
    Here is a Sample Access Database that can use jpeg or gif as pictures...

    I hope this would help.

    Saqib


    (Here you I've used the technique of only saving the path of the picture in the database and not the acutal picture and therefore a it is a better way to keep the size of your database under control and use jpegs and gifs in access)
    Attached Files Attached Files

  14. #14
    Join Date
    Nov 2002
    Location
    Norway
    Posts
    239

    Talking

    Thanks to all off you that has contributed.
    I think we now have a better understanding of the problem with OLE objects in Access.
    (can we propose for Mr. Bugg to improve this function ?)

    have a nice summer to all of you, take good care.

    Sincerely
    Vestigo

  15. #15
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    Somebody had mentioned stability, corruption and keeping the size under control.

    The method I am employing of storing images in the db will actually work for any file type. I am not embedding nor relying on OLE conversion. I am opening the file in binary format and storing the actual binary information that comprises the file in Long Integer format, along with it's original filename and extension as text fields.

    As an added precaution, it keeps the "stored" files in a seperate BE db with the table linked to my primary BE.

    I control file size on the front end - in my case, I limit the files to 256 KB as a 256 KB JPEG file has more than enough image quality for the application I'm developing.

    My client has experienced zero issues with stability and corruption - after all, I'm writing 1's and 0's to the db, nothing more.

    For Vestigo's single image application to store the company logo, you could either use a linked file, or to keep it fully self contained, have a seperate table with 1 OLE field and paste the image directly to that field.

    On forms and reports, use an OLE control and set the field of that table as the recordsource, or if you use a linked file, use the picture control and set the path programatically.

    My method would work as well, although it would be overkill for a single image.

    Have fun!
    have fun!

    Todd S.
    click to email


    Independent Development Consultant
    Biz db & reports - SQL, Access, Crystal, Seradex and more
    Small, custom, unique programs - Office, VBA, .NET


    _________________________________________________
    Favorite message from Windows:
    There was an error displaying the previous error message

    Sadly, there was no error number to look up ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •