1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377
| Public Sub scan(size As String, strdocnumber As String)
'Size has two values: "Yes" and "No". A "yes" means that the user is scanning a legal size document.
'A "no" means that the user is scanning an 8.5 x 11 document
'strDocument normally says "1". Sometimes, our client has 2 versions of the same document.
'So users can change the strDocument to a "2" which would merely create a 2nd version of the same document
On Error GoTo Err_Handler
Dim strFileName As String
strFilename = "filename"
If strdocnumber <> "1" Then
strFileName = strFileName & " Doc " & strdocnumber
End If
End If
'Now begin code for scanner
'Must include reference to Microsoft Windows Image Acquisition 2.0 dll
Dim Dialog1 As New wia.CommonDialog, DPI As Integer, PP As Integer, l As Integer
DPI = 600
PP = 4 'No of pages
Dim Scanner As wia.device
Set Scanner = Dialog1.ShowSelectDevice(wia.WiaDeviceType.ScannerDeviceType, False, False)
Scanner.Items(1).properties("6146").Value = 4 'Colour intent
Scanner.Items(1).properties("6147").Value = DPI 'DPI horizontal
Scanner.Items(1).properties("6148").Value = DPI 'DPI vertical
Scanner.Items(1).properties("6149").Value = 0 'x point to start scan
Scanner.Items(1).properties("6150").Value = 0 'y point to start scan
Scanner.Items(1).properties("6151").Value = 8.27 * DPI 'Horizontal extent
If size = "Yes" Then
Scanner.Items(1).properties("6152").Value = 14# * DPI 'Vertical extent for legal
ElseIf size = "No" Then
Scanner.Items(1).properties("6152").Value = 11# * DPI 'Vertical extent for letter
End If
'NOTE: the next 2 lines are optional. With the Brother DS600 mobile scanner, we found that the client's
'documents looked better if we tweaked the scanner's default settings for brightness and contrast
Scanner.Items(1).properties("6154").Value = -30 'brightness
Scanner.Items(1).properties("6155").Value = 30 'contrast
Dim img As wia.ImageFile
Set img = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG As String
'NOTE: calculatefilelocation is a subroutine that automatically calculates the
'appropriate path on the network to store the file
strFileJPG = calculatefilelocation & strFileName & ".jpg"
If FileExists(strFileJPG) Then
Dim FSO As New FileSystemObject
FSO.DeleteFile (strFileJPG)
Set FSO = Nothing
End If
img.SaveFile (strFileJPG)
'End scanner code for 1st page
'start variable to count pages
Dim intPages As Integer
intPages = 1
'Prompt user if there are additional pages to scan
Dim Answer2 As String
Dim MyNote2 As String
MyNote2 = "Scan another page?"
Answer2 = MsgBox(MyNote2, vbQuestion + vbYesNo, "???")
If Answer2 = vbNo Then
GoTo StartPDFConversion
Else
Dim img2 As wia.ImageFile
Set img2 = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG2 As String
strFileJPG2 = CalculateFileLocation & strFileName & "2.jpg"
If FileExists(strFileJPG2) Then
Dim fso2 As New FileSystemObject
fso2.DeleteFile (strFileJPG2)
Set fso2 = Nothing
End If
img2.SaveFile (strFileJPG2)
intPages = intPages + 1
End If
'Prompt user if there are additional pages to scan
Dim Answer3 As String
Dim MyNote3 As String
MyNote3 = "Scan another page?"
Answer3 = MsgBox(MyNote3, vbQuestion + vbYesNo, "???")
If Answer3 = vbNo Then
GoTo StartPDFConversion
Else
Dim img3 As wia.ImageFile
Set img3 = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG3 As String
strFileJPG3 = CalculateFileLocation & strFileName & "3.jpg"
If FileExists(strFileJPG3) Then
Dim fso3 As New FileSystemObject
fso3.DeleteFile (strFileJPG3)
Set fso3 = Nothing
End If
img3.SaveFile (strFileJPG3)
intPages = intPages + 1
End If
'Prompt user if there are additional pages to scan
Dim Answer4 As String
Dim MyNote4 As String
MyNote4 = "Scan another page?"
Answer4 = MsgBox(MyNote4, vbQuestion + vbYesNo, "???")
If Answer4 = vbNo Then
GoTo StartPDFConversion
Else
Dim img4 As wia.ImageFile
Set img4 = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG4 As String
strFileJPG4 = CalculateFileLocation & strFileName & "4.jpg"
If FileExists(strFileJPG4) Then
Dim fso4 As New FileSystemObject
fso4.DeleteFile (strFileJPG4)
Set fso4 = Nothing
End If
img4.SaveFile (strFileJPG4)
intPages = intPages + 1
End If
'Prompt user if there are additional pages to scan
Dim Answer5 As String
Dim MyNote5 As String
MyNote5 = "Scan another page?"
Answer5 = MsgBox(MyNote5, vbQuestion + vbYesNo, "???")
If Answer5 = vbNo Then
GoTo StartPDFConversion
Else
Dim img5 As wia.ImageFile
Set img5 = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG5 As String
strFileJPG5 = CalculateFileLocation & strFileName & "5.jpg"
If FileExists(strFileJPG5) Then
Dim fso5 As New FileSystemObject
fso5.DeleteFile (strFileJPG5)
Set fso5 = Nothing
End If
img5.SaveFile (strFileJPG5)
intPages = intPages + 1
End If
'Prompt user if there are additional pages to scan
Dim Answer6 As String
Dim MyNote6 As String
MyNote6 = "Scan another page?"
Answer6 = MsgBox(MyNote6, vbQuestion + vbYesNo, "???")
If Answer6 = vbNo Then
GoTo StartPDFConversion
Else
Dim img6 As wia.ImageFile
Set img6 = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG6 As String
strFileJPG6 = CalculateFileLocation & strFileName & "6.jpg"
If FileExists(strFileJPG6) Then
Dim fso6 As New FileSystemObject
fso6.DeleteFile (strFileJPG6)
Set fso6 = Nothing
End If
img6.SaveFile (strFileJPG6)
intPages = intPages + 1
End If
'Prompt user if there are additional pages to scan
Dim Answer7 As String
Dim MyNote7 As String
MyNote7 = "Scan another page?"
Answer7 = MsgBox(MyNote7, vbQuestion + vbYesNo, "???")
If Answer7 = vbNo Then
GoTo StartPDFConversion
Else
Dim img7 As wia.ImageFile
Set img7 = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG7 As String
strFileJPG7 = CalculateFileLocation & strFileName & "7.jpg"
If FileExists(strFileJPG7) Then
Dim fso7 As New FileSystemObject
fso7.DeleteFile (strFileJPG7)
Set fso7 = Nothing
End If
img7.SaveFile (strFileJPG7)
intPages = intPages + 1
End If
'Prompt user if there are additional pages to scan
Dim Answer8 As String
Dim MyNote8 As String
MyNote8 = "Scan another page?"
Answer8 = MsgBox(MyNote8, vbQuestion + vbYesNo, "???")
If Answer8 = vbNo Then
GoTo StartPDFConversion
Else
Dim img8 As wia.ImageFile
Set img8 = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG8 As String
strFileJPG8 = CalculateFileLocation & strFileName & "8.jpg"
If FileExists(strFileJPG8) Then
Dim fso8 As New FileSystemObject
fso8.DeleteFile (strFileJPG8)
Set fso8 = Nothing
End If
img8.SaveFile (strFileJPG8)
intPages = intPages + 1
End If
'Prompt user if there are additional pages to scan
Dim Answer9 As String
Dim MyNote9 As String
MyNote9 = "Scan another page?"
Answer9 = MsgBox(MyNote9, vbQuestion + vbYesNo, "???")
If Answer9 = vbNo Then
GoTo StartPDFConversion
Else
Dim img9 As wia.ImageFile
Set img9 = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG9 As String
strFileJPG9 = CalculateFileLocation & strFileName & "9.jpg"
If FileExists(strFileJPG9) Then
Dim fso9 As New FileSystemObject
fso9.DeleteFile (strFileJPG9)
Set fso9 = Nothing
End If
img9.SaveFile (strFileJPG9)
intPages = intPages + 1
End If
'Prompt user if there are additional pages to scan
Dim Answer10 As String
Dim MyNote10 As String
MyNote10 = "Scan another page?"
Answer10 = MsgBox(MyNote10, vbQuestion + vbYesNo, "???")
If Answer10 = vbNo Then
GoTo StartPDFConversion
Else
Dim img10 As wia.ImageFile
Set img10 = Scanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)
Dim strFileJPG10 As String
strFileJPG10 = CalculateFileLocation & strFileName & "10.jpg"
If FileExists(strFileJPG10) Then
Dim fso10 As New FileSystemObject
fso10.DeleteFile (strFileJPG10)
Set fso10 = Nothing
End If
img10.SaveFile (strFileJPG10)
intPages = intPages + 1
End If
StartPDFConversion:
Dim strFilePDF As String
strFilePDF = CalculateFileLocation & strFileName & ".pdf"
'Check for existing PDF file
If FileExists(strFilePDF) = True Then
Dim Answer As String
Dim MyNote As String
MyNote = "A file already exists. Do you want to overwrite it?"
Answer = MsgBox(MyNote, vbQuestion + vbYesNo, "???")
If Answer = vbNo Then
'Code for No button Press
Exit Sub
Else
Dim fso44 As New FileSystemObject
fso44.DeleteFile (strFilePDF)
Set fso44 = Nothing
End If
Else
End If
DoCmd.SetWarnings False
'NOTE: scantemp in the following lines is a table in your Access database used just for this process
DoCmd.RunSQL "delete from scantemp"
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG & "')"
If intPages >= 2 Then
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG2 & "')"
End If
If intPages >= 3 Then
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG3 & "')"
End If
If intPages >= 4 Then
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG4 & "')"
End If
If intPages >= 5 Then
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG5 & "')"
End If
If intPages >= 6 Then
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG6 & "')"
End If
If intPages >= 7 Then
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG7 & "')"
End If
If intPages >= 8 Then
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG8 & "')"
End If
If intPages >= 9 Then
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG9 & "')"
End If
If intPages >= 10 Then
DoCmd.RunSQL "insert into scantemp (picture) values ('" & strFileJPG10 & "')"
End If
DoCmd.SetWarnings True
'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
Dim RptName As String
RptName = "rptScan"
DoCmd.OpenReport RptName, acViewDesign, , , acHidden
DoCmd.Close acReport, RptName, acSaveYes
DoCmd.OutputTo acOutputReport, RptName, acFormatPDF, strFilePDF
'Now delete all the temporary jpg files
Dim fso46 As New FileSystemObject
fso46.DeleteFile strFileJPG
If intPages = 2 Then
fso46.DeleteFile strFileJPG2
ElseIf intPages = 3 Then
fso46.DeleteFile strFileJPG2
fso46.DeleteFile strFileJPG3
ElseIf intPages = 4 Then
fso46.DeleteFile strFileJPG2
fso46.DeleteFile strFileJPG3
fso46.DeleteFile strFileJPG4
ElseIf intPages = 5 Then
fso46.DeleteFile strFileJPG2
fso46.DeleteFile strFileJPG3
fso46.DeleteFile strFileJPG4
fso46.DeleteFile strFileJPG5
ElseIf intPages = 6 Then
fso46.DeleteFile strFileJPG2
fso46.DeleteFile strFileJPG3
fso46.DeleteFile strFileJPG4
fso46.DeleteFile strFileJPG5
fso46.DeleteFile strFileJPG6
ElseIf intPages = 7 Then
fso46.DeleteFile strFileJPG2
fso46.DeleteFile strFileJPG3
fso46.DeleteFile strFileJPG4
fso46.DeleteFile strFileJPG5
fso46.DeleteFile strFileJPG6
fso46.DeleteFile strFileJPG7
ElseIf intPages = 8 Then
fso46.DeleteFile strFileJPG2
fso46.DeleteFile strFileJPG3
fso46.DeleteFile strFileJPG4
fso46.DeleteFile strFileJPG5
fso46.DeleteFile strFileJPG6
fso46.DeleteFile strFileJPG7
fso46.DeleteFile strFileJPG8
ElseIf intPages = 9 Then
fso46.DeleteFile strFileJPG2
fso46.DeleteFile strFileJPG3
fso46.DeleteFile strFileJPG4
fso46.DeleteFile strFileJPG5
fso46.DeleteFile strFileJPG6
fso46.DeleteFile strFileJPG7
fso46.DeleteFile strFileJPG8
fso46.DeleteFile strFileJPG9
ElseIf intPages = 10 Then
fso46.DeleteFile strFileJPG2
fso46.DeleteFile strFileJPG3
fso46.DeleteFile strFileJPG4
fso46.DeleteFile strFileJPG5
fso46.DeleteFile strFileJPG6
fso46.DeleteFile strFileJPG7
fso46.DeleteFile strFileJPG8
fso46.DeleteFile strFileJPG9
fso46.DeleteFile strFileJPG10
End If
Set fso46 = Nothing
MsgBox "Done!"
Err_Handler:
If Err.Description = "The user requested a scan and there are no documents left in the document feeder." Then
MsgBox "Please insert paper into the scanner.", vbCritical, "Warning"
Resume
Else
Debug.Print Err.Description
Exit Sub
End If
End Sub |
Partager