I need users to run a scanner from within an Access program but have the program only ask for the scanner ONCE (I need it to loop 1-10 times for each scanning session)

alevin16
alevin16 used Ask the Experts™
on
In my Access program on a form I have a button that allows the user to choose a scanner and then scan 1-10 items one at a time.  I have a loop which pauses so that the person can put on another sheet.  Currently though the user has to pick the scanner every time in the loop because I use this line:

Set wiaScanner = wiaDialog.ShowSelectDevice

The scanner popup appears, they click on the scanner they want and it runs beautifully.  The problem is that I only want them to pick the scanner once and then have the system remember their choice no matter if they are scanning 2 pages or 10 pages.  Currently the above line of code is inside the loop for scanning (where I set various scanner properties) but when I tried moving it outside the loop, on the second go around it would error out asking for an object (so I am assuming it forgot the scanner) so I moved it back inside the loop.

I have not been able to make this happen no matter what I try (I even tried sendkeys to manipulate the dialog box but that failed).

Does anyone know how I can have the system remember the selected scanner? Another option could be that the user puts 1-10 pages on the feeder, the scanner scans them all in at once and I use VBA to chop up the scanned pages into 1-10 individual files (this way I do not even need a loop and I can use the scanning code just once).

Thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Fabrice LambertConsulting
Distinguished Expert 2017

Commented:
Hi,

Unfortunatly, there isn't much I can say without source code.
Divination wasn't teached at school :p

Author

Commented:
Hello Fabrice Lambert

I will attach the code in a txt file.

Thanks
Your code can check whether wiaScanner is defined and, if it is, skip asking for it again.

Note there is no text file attached yet.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Author

Commented:
Hi hdhondt

I am going to try attaching it again, it claimed it was.

When I put the Set command outside of the loop (which I think is the defining) it would error out on the second time thru the loop (also when I moved the set outside of the loop I moved the set = nothing also outside of the loop)

Hopefully the code connects this time
Coding.txt
I am not a programmer, but it looks as if putting
Set wiaScanner = wiaDialog.ShowSelectDevice 

Open in new window

before the loop and
Set wiaScanner = Nothing

Open in new window

after the loop should work. What is the error message you get when you do that?
Fabrice LambertConsulting
Distinguished Expert 2017

Commented:
In other words:
Instanciate your object before the loop, and destroy it after the loop.

Author

Commented:
I did try that but I still got the error.  I will run it tomorrow and take a screenshot.
As far as I can tell, it should work, so the error message is important.

Another point. Looking at your code, the user is prompted for every page. It would be much better (as you suggest in your question) to put all pages in the ADF and let the scanner handle that part of the job. In that case, you don't even need to ask the user for the number of pages: just count the JPGs when the scan is finished.
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
<< it would error out on the second time thru the loop>>

 What was the error?

 and you certainly don't want to set it to nothing.....you want it to be outside the loop and hold it's value until your done with the loop.

Jim.
Jim Dettman (EE MVE)President / Owner
Most Valuable Expert 2017
Most Valuable Expert 2012

Commented:
I believe that once you have the scanner, then in the loop you will need to issue the command:

.ExecuteCommand(wiaCommandChangeDocument)

 That would tell it to load the next page in the document handler.

 I haven't worked with WIA before, but it seems like the issue is what you need to do with the device to have it scan another page.

 This:

Set wiaScanner = wiaDialog.ShowSelectDevice


Gets you the device, so you need to work with that in some way after you have it to process each scan.

Jim.

Author

Commented:
An intern who works with me actually came up with the answer. He defined this variable:    Dim wiaTemp As WIA.Device
Then he set the variable to the chosen scanner:     Set wiaScanner = wiaDialog.ShowSelectDevice
    Set wiaTemp = wiaScanner

It worked

Thanks everyone!
Commented:
See above

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial