Scan muli-page document in Access database (1 Viewer)

jsbarroso

Registered User.
Local time
Today, 00:24
Joined
May 3, 2013
Messages
49
I have business group who wants the ability to scan documents into an Access database form I administer for them. They want the scanned documents to be saved in PDF file format and place in a shared network folder rather than actually storing them in the database. Currently this business unit is scanning documents as pdf’s and saving them to their computer than, adding the file into an attachment field I have on the form.

Any help would be greatly appreciated.
 

jdraw

Super Moderator
Staff member
Local time
Today, 03:24
Joined
Jan 23, 2006
Messages
15,383
Here's an older example

http://www.access-programmers.co.uk/forums/showthread.php?t=131703

You store the link/path info in your database table and shell to the appropriate file.

I have also seen this done using a webrowser control on a form, and navigating to the appropriate file.It opens in the browser with the default program associated with the filetype (acrobat for pdf, irfanview for jpg etc).

Again the file name and path are stored in the database table. The files are stored on the file system.
 

a.sharma

Registered User.
Local time
Today, 12:54
Joined
Apr 22, 2013
Messages
20
Check the code below.
I am using it in one of my app to scan documents as image and converting them to pdf and saving on a network folder.

Give me some time to make a test db for you.
Meanwhile have a look at the code to get some inputs on how to go about this task.



Code:
Public Sub ScanDocs()
Const wiaFormatJPEG = "{B96B3CAE-0728-11D3-9D7B-0000F81EF32E}"
Dim strFileName As String
Dim Dialog1 As New WIA.CommonDialog, DPI As Integer, PP As Integer, l As Integer
Dim Scanner As WIA.Device
Dim img As WIA.ImageFile
Dim intPages As Integer
Dim strFileJPG As String
Dim i As Integer
Dim blnContScan As Boolean
Dim ContScan As String    'msgbox to chk if more pages are to be scanned
Dim PdfOverwrite As String        'msgbox to confirm pdf file overwite
Dim FSO As New FileSystemObject
Dim strFilePDF As String
Dim RptName As String
Dim strProcName As String
strProcName = "ScanDocs"
On Error GoTo Handle_Err

'empty the scantemp table
DoCmd.SetWarnings False
DoCmd.RunSQL "delete from scantemp"
DoCmd.SetWarnings True
strFileName = strDocType
'create a temp folder if it does not exists
CreateTempFolder
'if a temp folder is present, delete all files from it
DeleteFiles
'Code for scanning
'Must include reference to Microsoft Windows Image Acquisition 2.0 dll
blnContScan = True
intPages = 0
Do While blnContScan = True
    DPI = 200
    PP = 1 'No of pages
    Set Scanner = Dialog1.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, False, False)
    With Scanner.Items(1)
        .Properties("6146").Value = 1 'Colour intent (1 for color, 2 for grayscale, 4 for b & w)
        .Properties("6147").Value = DPI 'DPI horizontal
        .Properties("6148").Value = DPI 'DPI vertical
        .Properties("6149").Value = 0 'x point to start scan
        .Properties("6150").Value = 0 'y point to start scan
        .Properties("6151").Value = 8.27 * DPI 'Horizontal extent
        .Properties("6152").Value = 11.69 * DPI     'Vertical extent for letter
    End With
    Set img = Dialog1.ShowTransfer(Scanner.Items(1), wiaFormatJPEG, True)
    'Set img = Scanner.Items(1).Transfer(WIA.FormatID.wiaFormatJPEG)
    intPages = intPages + 1
    strFileJPG = strTempFolder & "\" & strFileName & Trim(Str(intPages)) & ".jpg"
'    If FSO.FileExists(strFileJPG) Then
'        FSO.DeleteFile (strFileJPG)
'    End If
'    Set FSO = Nothing
    img.SaveFile (strFileJPG)
    DoCmd.SetWarnings False
    DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG & "')"
    DoCmd.SetWarnings True
    Set Scanner = Nothing
    Set img = Nothing
    strFileJPG = ""
    'Prompt user if there are additional pages to scan
    ContScan = MsgBox("Scan another page?", vbQuestion + vbYesNo, "Continue...?")
    If ContScan = vbNo Then
        blnContScan = False
    End If
Loop
GoTo StartPDFConversion
StartPDFConversion:
    strFilePDF = strTempFolder & "\" & strFileName & ".pdf"
    If FSO.FileExists(strFilePDF) Then
        FSO.DeleteFile (strFilePDF)
    End If
    Set FSO = Nothing
'Now let's run an Access report called rptScan and output it to a PDF file on the network
'rptScan is an Access report whose recordsource is the scantemp table
RptName = "rptScan"
DoCmd.OpenReport RptName, acViewReport, , , acHidden
DoCmd.Close acReport, RptName, acSaveYes
DoCmd.OutputTo acOutputReport, RptName, acFormatPDF, strFilePDF
CustDocPath = strFilePDF
strFilePDF = ""
Handle_Exit:
    Exit Sub
Handle_Err:
    Select Case err.Description
        Case "The user requested a scan and there are no documents left in the document feeder."
            MsgBox "Please insert paper into the scanner.", vbCritical, "Warning"
            Resume
        Case "ID Not Found."
            MsgBox "Please check that your scanner is properly connected and powered on and try again later.", vbCritical, "Warning"
            Resume Handle_Exit
        Case "No such interface supported."
            MsgBox "Please check that your scanner is properly connected and powered on and try again later.", vbCritical, "Warning"
            Resume Handle_Exit
        Case "User cancelled."
            MsgBox "Scan cancelled by user.", vbCritical, "Warning"
            Resume Handle_Exit
        Case "The remote procedure call failed.."
            MsgBox "RPC failed. Please check scanner settings in windows.", vbCritical, "Warning"
            Resume Handle_Exit
        Case Else
            MsgBox "Oops! Something went wrong." & vbCrLf & vbCrLf & _
            "In Function:" & vbTab & strProcName & vbCrLf & _
            "Err Number: " & vbTab & err.Number & vbCrLf & _
            "Description: " & vbTab & err.Description, vbCritical, _
            "Error in " & Chr$(34) & strProcName & Chr$(34)
            Resume Handle_Exit
    End Select
End Sub
[\CODE]
 
_________________________
Ashok
 

jsbarroso

Registered User.
Local time
Today, 00:24
Joined
May 3, 2013
Messages
49
Ashok,

Thank for the quick response. A sample database would be great. I greatly appreciate all your assistance.
 

a.sharma

Registered User.
Local time
Today, 12:54
Joined
Apr 22, 2013
Messages
20
jsbarroso: please check the attached test db.
I think this should help you as it contains all the code that you might need to accomplish your multi-page scanning and much more.

Need any further help? Do post back.

Good Luck.

__________________
Ashok
 

Attachments

  • Test.accdb
    972 KB · Views: 2,837

marlind618

Registered User.
Local time
Today, 00:24
Joined
May 22, 2013
Messages
15
I think this is a solution for what I am trying to do. I want to click a button and have it scan. I downloaded the file but get an error ScanDocs Err Nuber:52 Bad File name or number. Any suggestion on what I need to change. I am using access 2013. Do I need to check references? I have confirmed that my printer is working. Thanks for the help.
 

a.sharma

Registered User.
Local time
Today, 12:54
Joined
Apr 22, 2013
Messages
20
marlind618: I have checked the file again and it is working as intended. I have disabled the error handling so you can go into the code to check which line is giving you the error. let me know about it. Access 2013 should not be any problem.
 

Attachments

  • Test.zip
    140.1 KB · Views: 2,124

marlind618

Registered User.
Local time
Today, 00:24
Joined
May 22, 2013
Messages
15
I downloaded the new database and enabled the content. I get the Run-time error '-2145320939 (80210015)': No WIA Device of the selected type is available. I am running I am running office.microsoft.com on line. I have installed a Lexmark Printer. And I appreciate your quick reply.
 

marlind618

Registered User.
Local time
Today, 00:24
Joined
May 22, 2013
Messages
15
This is the statement that comes up when I debug it.
Set Scanner = Dialog1.ShowSelectDevice(WIA.WiaDeviceType.ScannerDeviceType, False, False)
 

a.sharma

Registered User.
Local time
Today, 12:54
Joined
Apr 22, 2013
Messages
20
Change the statement as below
Set Scanner = Dialog1.ShowSelectDevice(WIA.WiaDeviceType.Scanner DeviceType, True, False)

Now it should show you a device selection box.
 

marlind618

Registered User.
Local time
Today, 00:24
Joined
May 22, 2013
Messages
15
Still error looks like I don't have in Access 2013 reference for Microsoft Windows Image Acquisition Library v2.0 How do I get that?
 

a.sharma

Registered User.
Local time
Today, 12:54
Joined
Apr 22, 2013
Messages
20
In the VBA window, go to tools > references and see if you have a check mark in front of Microsoft Windows Image Acquisition Library vx.x. If not, scroll down to locate it and put a check mark to add the reference.
 

marlind618

Registered User.
Local time
Today, 00:24
Joined
May 22, 2013
Messages
15
I have had to install Microsoft Windows Image Acquisition 2.0 I see the reference in my other databases but when I try yours it requires a password. I did download a clean copy of your last database but didn't know if you wanted to share your password.
 

a.sharma

Registered User.
Local time
Today, 12:54
Joined
Apr 22, 2013
Messages
20
Sorry for that. I have removed the password. Use this fresh attachment.
 

Attachments

  • Test.zip
    140.2 KB · Views: 2,532

marlind618

Registered User.
Local time
Today, 00:24
Joined
May 22, 2013
Messages
15
Still have an error message. My scanner is waiting any more ideas?
 

marlind618

Registered User.
Local time
Today, 00:24
Joined
May 22, 2013
Messages
15
Maybe because I am using a wireless all in 1 printer scanner? We are checking this out on another computer with a hardwired scanner. I will report back tomorrow.
 

aromano789

Registered User.
Local time
Today, 03:24
Joined
Feb 9, 2008
Messages
12
I was wondering what type of scanners are being used. Im looking to setup 3 users with some kind of desktop scanner on their desk. Does anyone have any recommendations?
 

jsbarroso

Registered User.
Local time
Today, 00:24
Joined
May 3, 2013
Messages
49
A Sharman,
Thank you for the test database. I am finally back on this project. I receive a compatibility warning between Access 2010 and 2007 when I open your test database. Would it be possible for you to save a copy compatible with Access 2007? When I try to create a new Access 2007 database and import all the content from your test database, I receive a compile error in line “Dim FSO As New FileSystemObject”. I have tried a number of things but no luck.
It is possible to create the entire scanning and attachment process on one form. The group that will be using the database would like to simplify the process. They would like to open a form enter a file name, some brief detail and select to attach an image or PDF file.
Any assistance will be great appreciated.
Thank you in advance.
 

Users who are viewing this thread

Top Bottom