How can I add this code to the storage location of my file before scanning and then convert it to a PDF file?

kurdi

New member
Local time
Today, 11:42
Joined
Oct 16, 2022
Messages
13
How can I add this code to the storage location of my file before scanning and then convert it to a PDF file?
I want to select a folder or through a combox before scanning my document.


Code:
Public Function feeder scan()
'Must include reference to Microsoft Windows Image Acquisition 2.0 dell

Sub SetTheMainPathForAttachments()
'Define the main path to save attachments
'Change the main path of attachments from here only
' ---------------
PathOfFile = "c:\scan\" ---> Not in this way

' Create a folder after making sure that it does not already exist
If Len(Dir(PathOfFile, vbDirectory)) = 0 Then
MkDir PathOfFile
End If
End Sub

On Error GoTo Handle_Err
Dim ComDialog As New wia.CommonDialog, DPI As Integer, PP As Integer, l As Integer
Dim wiaScanner As wia.Device
Dim wiaImg As wia.ImageFile
Dim intPages As Integer
Dim strFileJPG As String
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Dim blnContScan As Boolean
Dim ContScan As String 'msgbox to chk if more pages are to be scanned
Dim strFilePDF As String
Dim RptName As String
Dim strProcName As String
Dim picfullname
strProcName = "ScanDocs"
blnContScan = True
Dim Counter As Integer

'Number is 150,200,300,400,500,600,1200
DPI = DLookup("[DPI]", "DPI")

If Len(Dir(PathOfFile & Forms![Form1]![IDD], vbDirectory)) = 0 Then
MkDir PathOfFile & Forms![Form1]![IDD]
End If


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



Counter = 0

With wiaScanner.Items(1)
wiaScanner.Properties("3088").Value = 1
.Properties("6146").Value = DLookup("[Colour]", "DPI") '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 = DLookup("[Horizontal]", "DPI") * DPI 'Horizontal extent -A4 = 8.5
.Properties("6152").Value = DLookup("[Vertical]", "DPI") * DPI 'Vertical extent for letter -A4 = 11

End With


'Start Scan if err number -2145320957 Scan document finish
Do While Err.Number <> -2145320957 'error number is ADF status don't feed document

On Error GoTo here
Counter = Counter + 1

picfullname = PathOfFile & Forms![Form1]![IDD] & "\" & Forms![Form1]![IDD] & "-" & Format(Now, "d-m-yy_h-n-s") & Counter & ".jpg"
' ÎØæÉ ÓÍÈ ÇáÕæÑÉ

Set wiaImg = wiaScanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)



wiaImg.SaveFile picfullname

Set wiaImg = Nothing
strFileJPG = ""

' Add full name of pic in table images
'Must include reference to Microsoft office 16.0 database engine object libaray
Dim Ttb As Recordset
Set Ttb = CurrentDb.OpenRecordset("Image")
Ttb.AddNew
Ttb![IDD] = Forms![Form1]![IDD]
Ttb![Path] = picfullname
Ttb.Update


Forms![Form1]![ImagesSubform].Requery

Forms![Form1]![ImagesSubform].SetFocus
DoCmd.GoToRecord , , acLast


Loop
here:




Handle_Exit:

Exit Function


Handle_Err:

Select Case Err.Number

Case 2501
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, 0, _
"Error in " & Chr$(34) & strProcName & Chr$(34)
Resume Handle_Exit
End Select

End Function




t
Public Function feeder scan()
'Must include reference to Microsoft Windows Image Acquisition 2.0 dell

Sub SetTheMainPathForAttachments()
'Define the main path to save attachments
'Change the main path of attachments from here only
' ---------------
PathOfFile = "c:\scan\" ---> Not in this way

' Create a folder after making sure that it does not already exist
If Len(Dir(PathOfFile, vbDirectory)) = 0 Then
MkDir PathOfFile
End If
End Sub

On Error GoTo Handle_Err
Dim ComDialog As New wia.CommonDialog, DPI As Integer, PP As Integer, l As Integer
Dim wiaScanner As wia.Device
Dim wiaImg As wia.ImageFile
Dim intPages As Integer
Dim strFileJPG As String
Dim rsParent As DAO.Recordset2
Dim rsChild As DAO.Recordset2
Dim blnContScan As Boolean
Dim ContScan As String 'msgbox to chk if more pages are to be scanned
Dim strFilePDF As String
Dim RptName As String
Dim strProcName As String
Dim picfullname
strProcName = "ScanDocs"
blnContScan = True
Dim Counter As Integer

'Number is 150,200,300,400,500,600,1200
DPI = DLookup("[DPI]", "DPI")

If Len(Dir(PathOfFile & Forms![Form1]![IDD], vbDirectory)) = 0 Then
MkDir PathOfFile & Forms![Form1]![IDD]
End If


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



Counter = 0

With wiaScanner.Items(1)
wiaScanner.Properties("3088").Value = 1
.Properties("6146").Value = DLookup("[Colour]", "DPI") '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 = DLookup("[Horizontal]", "DPI") * DPI 'Horizontal extent -A4 = 8.5
.Properties("6152").Value = DLookup("[Vertical]", "DPI") * DPI 'Vertical extent for letter -A4 = 11

End With


'Start Scan if err number -2145320957 Scan document finish
Do While Err.Number <> -2145320957 'error number is ADF status don't feed document

On Error GoTo here
Counter = Counter + 1

picfullname = PathOfFile & Forms![Form1]![IDD] & "\" & Forms![Form1]![IDD] & "-" & Format(Now, "d-m-yy_h-n-s") & Counter & ".jpg"
' ÎØæÉ ÓÍÈ ÇáÕæÑÉ

Set wiaImg = wiaScanner.Items(1).Transfer(wia.FormatID.wiaFormatJPEG)



wiaImg.SaveFile picfullname

Set wiaImg = Nothing
strFileJPG = ""

' Add full name of pic in table images
'Must include reference to Microsoft office 16.0 database engine object libaray
Dim Ttb As Recordset
Set Ttb = CurrentDb.OpenRecordset("Image")
Ttb.AddNew
Ttb![IDD] = Forms![Form1]![IDD]
Ttb![Path] = picfullname
Ttb.Update


Forms![Form1]![ImagesSubform].Requery

Forms![Form1]![ImagesSubform].SetFocus
DoCmd.GoToRecord , , acLast


Loop
here:




Handle_Exit:

Exit Function


Handle_Err:

Select Case Err.Number

Case 2501
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, 0, _
"Error in " & Chr$(34) & strProcName & Chr$(34)
Resume Handle_Exit
End Select

End Function
 

Attachments

Last edited by a moderator:
Welcome to Access World! We're so happy to have you join us as a member of our community. As the most active Microsoft Access discussion forum on the internet, with posts dating back more than 20 years, we have a wealth of knowledge and experience to share with you.

We're a friendly and helpful community, so don't hesitate to ask any questions you have or share your own experiences with Access. We're here to support you and help you get the most out of this powerful database program.

To get started, we recommend reading the post linked below. It contains important information for all new users of the forum:

https://www.access-programmers.co.uk/forums/threads/new-member-read-me-first.223250/

We hope you have a great time participating in the discussion and learning from other Access enthusiasts. We look forward to having you around!
 
How can I add this code to the storage location of my file before scanning and then convert it to a PDF file?
Not understanding what you want. What does "add this code to the storage location" mean?

Probably should have posted into a particular topic forum, other than "Introduce Yourself" because you present an issue, not just an introduction.

Also, please post code between CODE tags to retain indentation and readability.
 
First, welcome to the forums.

Second, that wall of code doesn't really help us. Tell us in common language what problem you were trying to solve. It is clear that you have a scanner and will be accepting an image from it, and you want to embed the image somewhere, but your question is ONE SENTENCE of problem and dozens of lines of code. Initial problem descriptions should be the other way around so we can get the idea of where you are going.

Third, you posted in our Introduction forum, but since you included a distinct problem discussion, it belongs in one of the technical forums. After we see your response regarding what you wanted to do, one of the moderators will move your question to an appropriate topic-oriented section. Do not feel that you have done anything wrong. To have a new member post in the wrong location is NOT a new occurrence for any of us.
 
Not understanding what you want. What does "add this code to the storage location" mean?

Probably should have posted into a particular topic forum, other than "Introduce Yourself" because you present an issue, not just an introduction.

Also, please post code between CODE tags to retain indentation and readability.
Brother I have put the file for you I want to add in this code for me how to save my file as a PDF
 
First, welcome to the forums.

Second, that wall of code doesn't really help us. Tell us in common language what problem you were trying to solve. It is clear that you have a scanner and will be accepting an image from it, and you want to embed the image somewhere, but your question is ONE SENTENCE of problem and dozens of lines of code. Initial problem descriptions should be the other way around so we can get the idea of where you are going.

Third, you posted in our Introduction forum, but since you included a distinct problem discussion, it belongs in one of the technical forums. After we see your response regarding what you wanted to do, one of the moderators will move your question to an appropriate topic-oriented section. Do not feel that you have done anything wrong. To have a new member post in the wrong location is NOT a new occurrence for any of us.
Brother I have put the file for you I want to add in this code for me how to save my file as a PDF
 
I want to select a folder or through a combox before scanning my document؟
 
Hi. Welcome to AWF!

Just FYI, I have moved your thread out of the Introduction Forum. Please feel free to start a new thread there to introduce yourself.

In the meantime, you might also consider posting some screenshots to help describe what you're trying to achieve.
 
Hi. Welcome to AWF!

Just FYI, I have moved your thread out of the Introduction Forum. Please feel free to start a new thread there to introduce yourself.

In the meantime, you might also consider posting some screenshots to help describe what you're trying to achieve.
 
Hi. Welcome to AWF!

Just FYI, I have moved your thread out of the Introduction Forum. Please feel free to start a new thread there to introduce yourself.
Seems to be a habit of theirs :(
 
Last edited:
@kurdi - a direct message doesn't give other members a chance to try to understand your problem. Direct messages have their uses but this wasn't one of them. I'm not angry that you directly contacted me, I'm just pointing out that by keeping the messages within the problem thread, you get greater exposure and thus a better chance to get a meaningful answer. It isn't annoying that you direct-messaged me; it is just not as productive as it could be.

I'm not up on direct connection to scanners so I have to ask - from where did you get this code?

As to how you connect it, I would GUESS (and this is no more than an educated guess) that you would place this code somewhere in the VBA section of a form that has a "SCAN" command button. Then you might call this code from the SCAN button_Click event. But I could be wrong on this. As a matter of security I don't usually open someone else's database so I'm not sure beyond that suggestion.
 
You simply replace the value from the filedialog for your hardcoded path.

Lookup the syntax for FileDialog.
 
Build the file dialog code in a Function procedure that can be called by the scan procedure and return the user's selected folder.

PathOfFile = GetFolderPath()
 
@kurdi - a direct message doesn't give other members a chance to try to understand your problem. Direct messages have their uses but this wasn't one of them. I'm not angry that you directly contacted me, I'm just pointing out that by keeping the messages within the problem thread, you get greater exposure and thus a better chance to get a meaningful answer. It isn't annoying that you direct-messaged me; it is just not as productive as it could be.

I'm not up on direct connection to scanners so I have to ask - from where did you get this code?

As to how you connect it, I would GUESS (and this is no more than an educated guess) that you would place this code somewhere in the VBA section of a form that has a "SCAN" command button. Then you might call this code from the SCAN button_Click event. But I could be wrong on this. As a matter of security I don't usually open someone else's database so I'm not sure beyond that suggestion.
thanks
 

Users who are viewing this thread

Back
Top Bottom