Loop For Next in a shell

  • Thread starter Thread starter GolfBag
  • Start date Start date
G

GolfBag

I want to use Access to open a shell to another program
and I can do that. Now I want to use send keys which will
work on one instance, but I really need to do a for I = 10
kind of thing so I can get it to send the series of keys
10 times. It won't work; does anybody know if this is
possible? Any help would be appreciated.
 
GolfBag said:
I want to use Access to open a shell to another program
and I can do that. Now I want to use send keys which will
work on one instance, but I really need to do a for I = 10
kind of thing so I can get it to send the series of keys
10 times. It won't work; does anybody know if this is
possible? Any help would be appreciated.

The problem with the he above approach is that it is so un-reliable..that
you can't trust this. In other words...sendkeys is not very useful. Hitting
a mouse..bumping a key while the process runs..accident switching to another
program that will then grab the keys strokes...sending keystroke too fast to
the program..etc .etc etc. Any one of these things happens..and your code
will fail.

So, in some cases you might get the keypress idea to work..but it is just so
full of so many things that can go wrong, that the end result is something
that is so un-reliable and so buggy as to be useless. (besides..you likely
do want to be viewed as creating buggy and un-reliable software..do you?).

So, I would find out if you can create some batch file, or can automate the
other application. (so, for example..when we launch word...you can insert
characters into a document..but you use "automation" and not sendkeys to do
this. I would find out of the other application you are using can be
automated (most good commercial windows programs can be automated).

SendKeys should be your last resort after you eliminated every other
possible approach..(and, have to realize that sendkeys is not reliable).
 
Albert,

Thanks for responding to my post. However, I have read
the rhetoric that is already out there on why not to use
Sendkeys, and I wouldn't use them if I didn't have to.
Still my question is unanswered. I do know that once you
use a shell from Access, you can use send keys. What I
want to do is use a for next loop, but the code just won;t
work. You got any experience in this area?
 
It is possible that your code is NOT waiting for the shell command to
finish?

The shell command starts..but the ms-access code starts to continue. Likely,
the shell application has not yet even loaded, and have the focus..so how
can it start to accept sendkeys yet? (it is not even running, or loaded).

Once again..you can see how problematic sendkeys will be.

You could start fooling around with some type of delay to wait until the
shell command program loads..and THEN start to send the keys...
...but then again..load time of software varies very widely.

You could also check up the following code that waits for the shell
command..but I don't believe that this following code will help..as it is
code to WAIT until the shell command is actually done. However, you can play
with the code...it is here:

API: Shell and Wait
http://www.mvps.org/access/api/api0004.htm

And you can also check out:
General: Run Dos Batch files from Access
http://www.mvps.org/access/general/gen0015.htm
You got any experience in this area?

Enough to know what you are creating is not going to be reliable....and
enough to know that I would not want the image of a developer who makes
un-reliable code..
 
<<...and I wouldn't use them if I didn't have to.>>
Albert provided good advice, and was politely prompting you to disclose what
you're actually trying to so, so he may perhaps help you in ways you weren't
aware of. There may be other ways to do whatever it is you're trying to do.

So the question is, "what are you trying to do?"

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Microsoft Access 2003 VBA Programmer's Reference
http://www.wiley.com/WileyCDA/WileyTitle/productCd-0764559036.html
 
Back
Top