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)

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
alevin16Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fabrice LambertFabrice LambertCommented:
Hi,

Unfortunatly, there isn't much I can say without source code.
Divination wasn't teached at school :p
0
alevin16Author Commented:
Hello Fabrice Lambert

I will attach the code in a txt file.

Thanks
0
hdhondtCommented:
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.
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

alevin16Author 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
0
hdhondtCommented:
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?
0
Fabrice LambertFabrice LambertCommented:
In other words:
Instanciate your object before the loop, and destroy it after the loop.
0
alevin16Author Commented:
I did try that but I still got the error.  I will run it tomorrow and take a screenshot.
0
hdhondtCommented:
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.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
<< 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.
0
Jim Dettman (Microsoft MVP/ EE MVE)President / OwnerCommented:
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.
0
alevin16Author 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!
0
alevin16Author Commented:
See above
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Printers and Scanners

From novice to tech pro — start learning today.