Results 1 to 6 of 6
  1. #1
    yasser hamdy is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    5

    Scan from ADF as PDF

    Hi all ,
    Has anyone please have a code to handle ADF to make scan for the documents ?
    I do one to scan from flatbed scanner , but i need to use the ADF .


    Thanks a lot .

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    something like:

    load the scanning DLL into vba:
    1. in access, press F11 (to enter vba)
    2. menu: tools, references
    load the generic WIA dll (or your scanner brand's dll) to talk to the scanner
    3. close references
    4. put the code below onto a module then call it via: ScanDoc


    Code:
    Public Sub ScanDoc()
    'The WIA (Windows Image Acquisition Automation Library v2.0 Tool).
    ' WIAAut.dll
    
    
    Dim Cd1 As WIA.CommonDialog
    Dim img As ImageFile
    Dim vTargFile, vFormat, vFileName
    
    
    On Error GoTo errScan
    
    
    vFormat = "pdf"
    Type_Of_Document = vFormat
    
    
    '------------
    vFileName = "4455" & "." & vFormat
    docPath = "e:\"
    
    
    'vFileName = Document_ID & "." & vFormat
    vTargFile = docPath & vFileName
    '------------
    
    
    Set Cd1 = CreateObject("wia.commondialog")
    Set img = Cd1.ShowAcquireImage
    
    
    'KillFile vTargFile   'erase prev version
    img.SaveFile (vTargFile)
    
    
    Set img = Nothing
    Set Cd1 = Nothing
    Exit Sub
    errScan:
    MsgBox Err.Description, , "ScanDoc:" & Err
    End Sub

  3. #3
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Fwiw I like to use the software NAPS2. It's free scanning software that can also be used from the command line. Within NAPS you set up different named 'profiles', ie flatbed, adf, size, color, resolution, etc. Then you can simply call naps along with a preset profile from the command line. I call the command line from access using the shell command. If you're interested in this approach ill be happy to share some code tomorrow when I have access to it.

  4. #4
    yasser hamdy is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Mar 2021
    Posts
    5
    Thanks , but how i can use it in access , can you please tell me how to press a button in form so the scanner start to scan the documents which are in ADF and save it in PDF format ?

  5. #5
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    i gave you step-by-step instructions.
    in addition, on a form , add a button.

    in the button ON CLICK event, add ScanDoc

    Code:
    sub btnScan_click()
      scandoc
    end sub

  6. #6
    kd2017 is offline Well, I tried at least.
    Windows 10 Access 2016
    Join Date
    Jul 2017
    Posts
    1,142
    Here is my simple code that suits my needs, maybe you'll find it useful:

    Code:
    Option Compare Database
    Option Explicit
    
    'NAPS console usage: https://www.naps2.com/doc-command-line.html
    
    'CHANGE THIS to where ever the naps2 executable is installed on your computer
    Const NAPS2Path As String = "C:\Program Files (x86)\NAPS2\NAPS2.Console.exe"
    
    
    'this sub will execute a shell command and wait for execution to finish
    Public Sub RunCmd(cmd As String)
    On Error GoTo ErrHandler_RunCmd
        'https://stackoverflow.com/questions/15951837/wait-for-shell-command-to-complete
        Dim wsh As Object
        Set wsh = VBA.CreateObject("WScript.Shell")
        Dim waitOnReturn As Boolean: waitOnReturn = True
        Dim windowStyle As Integer: windowStyle = 1
        'Debug.Print cmd
        wsh.Run cmd, windowStyle, waitOnReturn
        
    ExitHandler_RunCmd:
        Set wsh = Nothing
        Exit Sub
        
    ErrHandler_RunCmd:
        Resume ExitHandler_RunCmd
    End Sub
    
    Public Sub NAPS2Scan(output As String, Optional profile As String = "Glass", Optional num_of_scans As Byte = 1, Optional delay As Long = 0, Optional wait As Boolean = True)
    On Error GoTo ErrHandler_scan
        Dim cmd As String
        cmd = """" & NAPS2Path & """ -o """ & output & """"
        'NAPS console usage: https://www.naps2.com/doc-command-line.html
        If profile <> "" Then cmd = cmd & " -p """ & profile & """" 'Specifies the name of the profile to use when scanning. Profiles are defined using the GUI. If this option is not specified, the most-recently-used profile from the GUI is selected.
        cmd = cmd & " -n " & num_of_scans 'The number of scans to perform. This may be different from the number of pages scanned (e.g. if you have an automated document feeder).
        cmd = cmd & " -d " & delay 'The delay (in milliseconds) between each scan.
        If wait Then cmd = cmd & " -w" 'After finishing, wait for user input (enter/return) before exiting
        cmd = cmd & " -v" 'Displays progress information.
        cmd = cmd & " --progress" 'Displays a graphical window for scanning progress
        cmd = cmd & " --disableocr" 'Specifies that OCR should NOT be used when generating PDFs. Overrides --enableocr.
        
        'Debug.Print cmd
        RunCmd cmd
    
    ExitHandler_scan:
        Exit Sub
        
    ErrHandler_scan:
        Resume ExitHandler_scan
    End Sub
    So let's say you set up a scanning 'profile' in the naps2 gui called 'ADF' to scan from the adf, you would simply run the scanner like this
    Code:
    NAPS2Scan "D:\Test.pdf", "ADF"

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Can not scan barcodes that contain slash
    By goldenberg1957 in forum Access
    Replies: 4
    Last Post: 03-26-2021, 08:20 AM
  2. Barcode Scan
    By harhar0506 in forum Forms
    Replies: 8
    Last Post: 06-29-2017, 01:30 PM
  3. Bar code scan
    By Magnus1982 in forum Forms
    Replies: 1
    Last Post: 05-05-2017, 02:39 AM
  4. Scan Into Folder
    By angie in forum Programming
    Replies: 1
    Last Post: 01-12-2016, 01:45 PM
  5. Scan WIA with ADF error after first page
    By wackywoo105 in forum Programming
    Replies: 15
    Last Post: 11-11-2015, 02:45 PM

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