Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34

    Scan WIA with ADF error after first page

    I’m trying to scan multiple A4 pages to jpegs using WIA and ImageProcess from the auto-document feeder on my scanner.

    Individual scans work fine as does the first scan from the document feeder. These are scanned and saved fine. The process fails during the second document from the feeder with the message: Error No -2147024809: The parameter is incorrect. At this point the scanner just stops with the page half fed through.



    Can anyone see where I am going wrong with the following code? I have tried a few variations but none of them work for a second document.

    Code:
    Private Sub Scan_Click()
    On Error GoTo Err_Handler
    Dim info As String
    info = InputBox("Please enter scan description.", "Scan information.")
    If IsValidFileName(info) = False Then
        MsgBox "The following characters cannot be used in the description:" & vbCrLf & vbCrLf & " \  /  :  *  ?  <  >  |  " & Chr(34)
        Exit Sub
    End If
    
    MsgBox "Please load the document you wish to scan and click ok."
    Dim wiaImg As New WIA.ImageFile
    Dim wiaDialog As New WIA.CommonDialog
    Dim wiaScanner As WIA.Device
    Dim IP As ImageProcess
    Set IP = CreateObject("WIA.ImageProcess")
    IP.Filters.Add (IP.FilterInfos("Convert").FilterID)
    IP.Filters(1).Properties("FormatID").Value = WIA.FormatID.wiaFormatJPEG
    IP.Filters(1).Properties("Quality").Value = 25
    Set wiaScanner = wiaDialog.ShowSelectDevice
    'MsgBox wiaScanner.Properties.item("3087").Value
    Dim counter As Integer
    counter = 1
    ADFStatus = True
    
    While ADFStatus
    With wiaScanner.Items(1)
    If ScanColour = True Then
        .Properties("6146").Value = 1 '4 is Black-white,gray is 2, color 1 (Color Intent)
    Else
        .Properties("6146").Value = 2 '4 is Black-white,gray is 2, color 1 (Color Intent)
    End If
        .Properties("6147").Value = 200 'dots per inch/horizontal was set at 100
        .Properties("6148").Value = 200 'dots per inch/vertical was set ao 100
        .Properties("6149").Value = 0 'x point where to start scan
        .Properties("6150").Value = 0 'y-point where to start scan
        'Following is A4 paper size. _
        '(Not 100% accurate because real A4 Ht errors)
        .Properties("6151").Value = 1660 'horizontal exent DPI x inches wide
        .Properties("6152").Value = 2334 'vertical extent DPI x inches tall
         Set wiaImg = .Transfer(wiaFormatJPEG) 'Change file type in save to match format
    End With
    Set wiaImg = IP.Apply(wiaImg)
    If counter = 1 Then
        wiaImg.SaveFile (gdrive & "Scan\" & Format(Date, "yyyy_mm_dd") & "_" & Format(Time, "hh_mm_ss") & "_" & info & ".jpg")
    Else
        wiaImg.SaveFile (gdrive & "Scan\" & Format(Date, "yyyy_mm_dd") & "_" & Format(Time, "hh_mm_ss") & "_" & info & "_" & counter & ".jpg")
    End If
    
        ADFStatus = wiaScanner.Properties.item("3087").Value
        counter = counter + 1
        
      Set wiaImg = Nothing
    Wend
    
    Set wiaScanner = Nothing
    Exit_Sub:
     Exit Sub
    Err_Handler:
     strMsg = "Error No " & Err.number & ": " & Err.Description
     MsgBox strMsg, vbExclamation, "Scan error."
     Resume Exit_Sub
    End Sub

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Which line triggers the error? Disable the error handler so you can debug - comment the On Error GoTo line.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34
    It fails on the
    Code:
    Set wiaImg = .Transfer(wiaFormatJPEG) 'Change file type in save to match format
    line the second time round.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,902
    Is WIA an add-in? I am not finding it in VBA references. I tried to use the code but getting compile error "User defined type not found" on the wiaImage declaration.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I do not have experience working directly with WIA. Instead, I use a custom class that takes a lot of the guesswork out. What it looks like to me is that you are trying to use an existing image handle before the scanner is done with it. You need to add something to your code that will determine when the scanner is finished.

    I found the following link
    http://forums.codeguru.com/showthrea...ion-(WIA)-Code

    I would suggest testing for a connection property. It looks like you might have the correct one here
    wiaScanner.Properties.item("3087").Value

    So maybe you can do a debug.print and compare a single page to a multipage.
    Code:
    ...
    Dim objProps as Object
    While ADFStatus
    With wiaScanner.Items(1)
    
    ...
    
    debug.print wiaScanner.Properties.item("3087").Value
    '     Set wiaImg = .Transfer(wiaFormatJPEG) 'Change file type in save to match format
    I am guessing you need to use the Transfer method after the multipage is finished with that image handle.

  6. #6
    HiTechCoach's Avatar
    HiTechCoach is offline MS MVP - Access Expert
    Windows 8 Access 2013
    Join Date
    Jul 2010
    Location
    Oklahoma, USA
    Posts
    702

  7. #7
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34
    Quote Originally Posted by HiTechCoach View Post
    Yes I have posted in two places to see if I get more responses.

  8. #8
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34
    Having played around and trying to put the scan code into a function it does appear that the second document is half loaded by the first instance of Set wiaImg = .Transfer(wiaFormatJPEG). This of course means when it is called again it doesn't work.

  9. #9
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34
    Well the fix was simple. .Properties("6152").Value = 2334 to .Properties("6152").Value = 2300 and all is fine. Realising it was loading the second sheet on the first call I figured maybe I had the length too long.

    Edit: Well not quite all done. Now it works for multiple images but never comes to an end and eventually switches to repeated flatbed scans. Nearly there though.

  10. #10
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    If you take a look at the link I provided, you will see that they use a constant
    WIA_RESERVED_FOR_NEW_PROPS = 1024

    Then they add a value to that. This is why I was suggesting to loop through ONE of the properties. Maybe you can see it change from one value to a range between 1037 and 1040.

    Consider this flow of statements
    Code:
    if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_SELECT)
     documentHandlingSelect = prop;
    if (prop.PropertyID == WIA_PROPERTIES.WIA_DPS_DOCUMENT_HANDLING_STATUS)
     documentHandlingStatus = prop;
    It seems this is what he is using to determine when the process of multipage is complete. In C#, == is equates to operator.

    So yeah, there may be a need to change property 6152 to another value that indicates it will be multi value (I am guessing this is what is happening). I am also guessing 3087 will equal a specific value when it is complete. I am guessing this because of ...
    ADFStatus = wiaScanner.Properties.item("3087").Value

    The following will loop until the value of ADFStatus is not -1
    Code:
    While ADFStatus

  11. #11
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34
    Thanks for all the input so far. I will have more of a look at the above as I have some free time today. I have fixed the repeated scan issue. It now stops after the final document has been fed through.

    The problem I have is that on some scans it pulls an extra page in and stops midway through scanning. It appears to be based on the length of the page. If I shorten it this stops happening (A4 at 200 dpi should be 11.7x200=2340). Of course this means the very bottom of all pages is missed off the scans. If I lengthen it the error starts to creep back. I need to put something in to stop it sucking another page in after it has scanned the first, and this is where I am currently stuck.

  12. #12
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    I do not know that I have any info that can help with this issue. If I was presented with this issue I would start to look at various settings applied to the Properties of the connection/device. It seems you are looking at this, now. In my experience, the scanner will manage most settings via its own default values. Different models manage this behavior differently. In short, I would try sending the least amount of information possible.

    I am not an expert with TWAINS, but the way I understand it, the TWAIN acts as an interface to the driver. The TWAIN is generic and the driver is specific to a peripheral. When your application talks to the driver, it needs to use commands the driver understands. My experience is an ADF will adjust for different paper sizes as the paper is scanned. It may seem intuitive to include assigning a size within your loop (While ADFStatus). I would try to use code and override default settings of the scanner outside the loop (as soon as you have the connection element defined). Actually, I would bring up the driver's UI and set the default via that. Manually scan a couple docs like that (using the default settings) and then run my code with the sizing code block commented out.

    If the ADF is grabbing two pages at once, you may have a worn roller or feeder or something else mechanically wrong with the ADF.

  13. #13
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34
    The problem is after scans the first page and saves it fine, for some reason it then starts to pull a second page in but does nothing with it. It just holds it there. When the second loop runs it fails because a document is half way through the feeder. The scanner works fine in a normal windows environment. I am just playing around deleting various properties to see if it defaults to something that works but ATM it still pulls in a second page after saving the first. The only way to stop this is to set the page length shorter which I don't want to do.

    There is a setting not to pre load the next page with ADF but when I try to set it I get ID not found error. https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    const ScanAheadPages = 3094

  14. #14
    ItsMe's Avatar
    ItsMe is offline Sometimes Helpful
    Windows 8 Access 2013
    Join Date
    Aug 2013
    Posts
    7,862
    The only way to stop this is to set the page length shorter which I don't want to do.
    No, you do not want to do that. In the end, there is no fighting it, you are going to have to reverse engineer a working example. I looked at a couple examples. One showed a VB6 version of the C# example I linked to earlier. This seems to be using version 1 and there might be another option for version2. I came across this ...
    wiaScanner.ExecuteCommand wiaCommandChangeDocument

    It uses a constant to tell a scanner to process all of the documents. If the scanner is set to use ADF, this may be an option for WIA v2.

    I tried executing some code to test a couple of things. My scanner is on default for Flatbed so I did not get very far. I started to wonder if I told the scanner to switch to ADF if it would begin to process multiple pages. And then I found this link.
    https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx

    The problem is I am not finding where to apply the above flags. I know in the custom class that I use, I can get the symptom you are describing if I tell the device to use single scan or sometimes if I tell it to use flatbed and there is something in the feeder (depending on brand of scanner) , it will only grab one page.

    As I mentioned, the examples out there seem to do a loop through the properties to look for 1038 within the wiaScanner.Items(1).Properties. I tried executing the following to look for the property, but my scanner was not even set to ADF. It is on flatbed.
    Code:
    Dim wiaDialog As New WIA.CommonDialog
    Dim wiaScanner As WIA.Device
    Dim prop As WIA.Property
    
    Set wiaScanner = wiaDialog.ShowSelectDevice
    Set prop = Nothing
    
        For Each prop In wiaScanner.Items(1).Properties
            Debug.Print prop.PropertyID
        Next prop

  15. #15
    wackywoo105 is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Mar 2014
    Posts
    34
    Thanks for your further input I really appreciate it. I will have more of a play when I have a bit more time but for now I have thrown in the towel. My scanner is a HP6310 and it doesn't play very nicely with windows 7 at the best of times so I'm not sure if the driver could be causing the problem. For now I have just given in and set the page length slightly short for ADF scans. Every other setting I tried to alter just generated an error. For some reason my code will use ADF or default to flatbed if nothing is present in ADF automatically. I test for using ADF and if its flatbed the length is set to full A4. To be fair the ADF scans don't miss much off the bottom and for what I currently want I can live with it.

    I have a Lexmark scanner at work and intend to try the code full length A4 on the ADF on that to see what happens on it.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Scan Snap IX500 Scanner
    By angie in forum Programming
    Replies: 3
    Last Post: 06-25-2015, 10:30 AM
  2. button to scan a document to pdf and save to folder
    By charlieb in forum Programming
    Replies: 2
    Last Post: 04-20-2015, 09:40 AM
  3. Scan File to folder location from access
    By wrbuchanan2 in forum Access
    Replies: 3
    Last Post: 04-26-2013, 10:26 PM
  4. Replies: 9
    Last Post: 10-13-2011, 01:30 PM
  5. Barcode Scan input
    By Nem3s1S in forum Database Design
    Replies: 4
    Last Post: 09-26-2009, 09:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums