vbams-accesswiascanning

Scan multiple pages with ADF scanner using VBA


I am writing a Microsoft Access application and I want to enable the user to scan multiple pages to a single PDF format. The conversion to PDF works fine once I have all the pages scanned. Here's my code:

Option Compare Database
Option Explicit

Const WIA_FORMAT_JPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"

Public Function MyScan()
  Dim ComDialog As WIA.CommonDialog
  Dim DevMgr As WIA.DeviceManager
  Dim DevInfo As WIA.DeviceInfo
  Dim dev As WIA.Device
  Dim img As WIA.ImageFile
  Dim i As Integer
  Dim wiaScanner As WIA.Device

  Set ComDialog = New WIA.CommonDialog
  Set wiaScanner = ComDialog.ShowSelectDevice(WiaDeviceType.UnspecifiedDeviceType, False, True)

  Set DevMgr = New WIA.DeviceManager

  For i = 1 To DevMgr.DeviceInfos().Count
    If DevMgr.DeviceInfos(i).DeviceID = wiaScanner.DeviceID Then
      Set DevInfo = DevMgr.DeviceInfos(i)
    End If
  Next i

  Set dev = DevInfo.Connect

  Set img = dev.Items(1).Transfer(WIA_FORMAT_JPEG)

  img.SaveFile "C:\img.jpg"

  Set img = Nothing
  Set dev = Nothing
  Set DevInfo = Nothing
  Set DevMgr = Nothing
  Set ComDialog = Nothing


End Function

Of course it is important to say that my scanner is Avision AV121 with an automatic document feeder.

My problem is that Set img = dev.Items(1).Transfer(WIA_FORMAT_JPEG) scans ALL the pages at once (and not just a single page) but I only see the first one in the image file. Because all the pages are scanned at once, I can't do it in a loop - an error will be raised in the second iteration (saying that the feeder is empty as it really is) and I still only have the first page scanned.

I would like to state that this seems to be a common problem. I've read a lot of threads regarding this problem, but didn't find anything that answered my question.

I hope to find help here, I am really frustrated.

Many thanks


Solution

  • I had this problem myself.

    I cannot remember where I found that this is probably a limitation of WIA, a bug I think. Maybe only in some circumstances.

    My solution was to use a 3rd party scanning control.