Results 1 to 8 of 8
  1. #1
    New Lounger
    Join Date
    Jul 2001
    Location
    New Zealand
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    VBA OLE code to get photo from scanner (Access 97)

    I wonder if anyone can help me, please.
    About 2 years ago, I prepared some code for a client that allowed them to transparently scan a photo from their scanner (an HP ScanJet), and store it into their database automatically. At the time it worked well. The client was happy, and used it infrequently.
    Now they (and I) have occassion to attempt to use it again, and lo and behold, it no longer works. I have struggled with this for quite a while, attempting to determine the reason that it has stopped working, to no avail (which is hardly surprising, as I dont know how it worked in the first place - the code was cribbed from somewhere else, and I cant remember from whence!).
    Basically, we have a table with 2 fields - an ID number, and an OLE Object field (labelled Photo).
    In the database we have a form linked to this table, with the field 'Photo' as a Bound Object Frame - the Class is "HP.PrecisionScanLT.1" (as this is accessing the PrecisionScan LT software that came with the printer), and the Update Option is Manual. There is also a button which when pressed (when it was working) executed the following code:

    Photo.Class = "HP.PrecisionScanLT.1"
    Photo.Verb = 1
    If IsNull(Photo) Then
    Photo.Action = acOLECreateEmbed
    Else
    Photo.Action = acOLEUpdate
    End If
    Photo.Action = acOLEActivate

    As above, originally this worked fine - on pressing the button, the scanner software would be started, then scan the image, and return the image to the OLE control on the form, thence to the database. Opening the form subsequently would simply display the already stored photo.

    Now we get a variety of errors - error 2771 (which I cannot interpret), crahses in the scanning software if it does get started), or hangs in the application.

    There have obviously been a lot of changes made in the respective systems since the application was properly working; we have been attempting to determine where the changes have been made, but this is like looking for a needle.

    Has anyone seen something similar to this, please, or can anyone advise of a 'better' (read working) way to get this process accomplished. Please note that this is still Access 97, and the client is not wanting to change this (financial reasons).

    Many thanks in advance.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: VBA OLE code to get photo from scanner (Access 97)

    I can't help you with your problem, but I have a warning: storing images in an Access database is a recipe for trouble - it will cause your database to bloat tremendously. Apart from the native format (TIFF, JPG, ...), Access always stores an uncompressed bitmap of the image. For a full color page scanned at 300 bpi, this will be ove 20 MB! The recommended way to handle images in a database is to store the images as separate files, and have a text field in the table that stores the file path. Charlotte has posted a sample database that demonstrates how to do this in <post#=126927>post 126927</post#>.

    You may be able to prevent your problem by adding proper error handling to your code.

    BTW, error 2771 means that the object frame doesn't contain an OLE object.

  3. #3
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: VBA OLE code to get photo from scanner (Access 97)

    MS Knowledge Base article 131934 describes the error message you are getting. In essence you are trying to insert an OLE object into an unbound object frame. It sounds as though something may have been renamed, or your database may be corrupt. How many records do you have, and how large is the database? As Hans noted, databases can grow like toppsy when you embed or link to graphic objects. Also, another question: What is Photo that you refer to in your code? It appears it may be some sort of OLE Automation object, so you may be missing a reference in your database that is causing your problems. Hope this generates some things to look at.
    Wendell

  4. #4
    New Lounger
    Join Date
    Jul 2001
    Location
    New Zealand
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA OLE code to get photo from scanner (Access 97)

    Hans, Thanks for the very prompt response, and for the pointer to Charlotte's code. Firstly, thanks for the warning about the picture size. I wasnt aware of this as a problem. Now that I look at the size of the database, it is obvious. There are currently not too many pictures stored, which is why we had not noted this as an issue, but with the likely number of new images to be stored, will become a problem.
    Charlotte's code is similar to what I had worked out to display pictures stored outside Access, but I still have the problem of allowing the user to scan and save new images, then link them into the database. We had been using a 'product-id' field value generated for the main product info stored in the database, and I had thought to ask the user to scan and save the pictures with some prefix with this as a suffix for storing the pictures. BUT, the user is a 'turkey', and needs to have everything driven for them.
    What I am really interested in, I guess, is some way of driving the scanner from within Access - I have managed to get the VBA code to start-up the scanning program, but can find no way to have it automatically scan the picture, then store it with a given name and type into a particular location. The original code sort of circumvented this problem (that is, when it was working!).
    As above, I have tried the Shell command, but this simply dumps the user into the standard scanner interface, whence he has to drive everything himself. Given the level of the user, this isnt practical.
    Have you come across any scanning / graphic programs or code that could be linked to from Access to scan and save in a given format/location?
    Again, thanks for your help and pointers.

    Ray

  5. #5
    New Lounger
    Join Date
    Jul 2001
    Location
    New Zealand
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA OLE code to get photo from scanner (Access 97)

    Confusion. Wendell, thanks for your response. I believed that I hadnt changed anything in this process. The 'photo' field is an OLE control on the form that is being displayed. Thanks for the pointer to the MS article.
    Given Hans' comments earlier and your comments about file sizes, I believe that this isnt the way to go for this project, but to pull back and put the files externally.
    As with Hans, have you come across any way of controlling the scan of, format, and storage location for pictures?
    THanks again
    Ray

  6. #6
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: VBA OLE code to get photo from scanner (Access 97)

    <P ID="edit" class=small>(Edited by WendellB on 30-Dec-02 17:36. Updated to show similar thread.)</P>Well, based on what I think I MIGHT know, I don't see any way of doing what you want without delving into the TWAIN driver in detail and writing a bunch of complicated code. There probably is documentation that will tell you how to do that, but methings it won't be a trivial exercise. What you have been doing may well be the simplest approach - the trick may be to save the image to a temporary table, and once the image has been stored, then open the record in VBA and save the object as an external file. That seems like a fair bit of work too, but you may find it better documented. Of course you would want to compact the database very frequently, as a few images will still cause it to bloat substantially. Sorry I can't be more helpful.

    You might also see if the thread starting with <post#=144906>post 144906</post#> stirs up any ideas. If you find a solution we would love to know how you did it.
    Wendell

  7. #7
    New Lounger
    Join Date
    Jul 2001
    Location
    New Zealand
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: VBA OLE code to get photo from scanner (Access 97)

    Wendell,
    Thanks again for your comments. I agree that the effort required to get TWAIN interface would be too great to work with.
    The original code I had was wonderfully simple - simply having a Bound Object Frame (named Photo), linked to an OLE field in the database (also called Photo). There was a button which the user could click when the scan was to occur with the code:

    Photo.Class = "HP.PrecisionScanLT.1"
    Photo.Verb = 1
    If IsNull(Photo) Then
    Photo.Action = acOLECreateEmbed
    Else
    Photo.Action = acOLEUpdate
    End If
    Photo.Action = acOLEActivate

    Originally this worked sweetly, but now gets apparently random crashes when it trys to run. Most frequent appears to be IPF in hpprsx.exe, but no clues as to what is causing it.

    Wish MS software platforms were 'stable'.

    Thanks again and best wishes for the coming year.

    Ray

  8. #8
    Super Moderator
    Join Date
    Aug 2001
    Location
    Evergreen, CO, USA
    Posts
    6,624
    Thanks
    3
    Thanked 60 Times in 60 Posts

    Re: VBA OLE code to get photo from scanner (Access 97)

    I suspect that new software has been installed on the PC you are trying to do this from, and it has clobbered one or more files. By chance has the OS been upgraded? The failure in hpprsx.exe is almost surely one of the scanner routines blowing up - you might check and see if there are later drivers for it. I have an ancient ScanJet IIcx and I simply cannot get it to run under WindowsME or XP - we ended up getting a USB scanner finally, which I should have done long ago instead of fiddling and trying to get the old one to work.
    Wendell

Posting Permissions

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