Access XP - W2K3 Std Srvr - Sendkeys - TS

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an Access XP db and I'm using SendKeys (yes I know it's ugly) to send
info to a legacy app. I've already tried to do file level information flow
and it doesn't work, so the last choice is sendkeys. It's running on Windows
Srvr Standard 2003, and I also want to use in throught terminal services.

It works fine on W2K using TS, fine on XP Pro stand alone.

All I'm doing is trying to take the values off text boxes and send to the
legacy app.
The legacy app is an form that stores it's own information into a single
seperate file with some kind of hash on them that changes even if you just
open and re-save the form.

Here's what I get:
Open Access, open legacy app, place cursor in proper spot on legacy app,
then go to Access and press send button.
First time always works like a charm. After that, it may take anywhere from
2 - 20 clicks on the button, and sometimes doesn't even work.

I use appactivate to get to the legacy app. I can't shell, becuase I have
to open the form and place the cursor where I want the information to end up.

Also, sometimes on the additional sending of information the first piece of
information isn't sent.

Also, when I click on the button the extra times, the focus is not moved to
the legacy app, but when I mouse off the access db, and over the legacy app
window it changes focus to it.

Any help would be greatly appreciated
Thx
Mark
 
I’m looking for answerers like you. AppActivate is behaving even more erratic
than it did in the past. However, there are some techniques that will permit
you to do what you want. I’ll try to explain them.

AppActivate “YourApplicaitonâ€, True

When you use AppActivate the Windows screen does not immediately open. There
is a delay. I observed “SendKeys “My Informationâ€, true†would often get only
“tion†in the field if you were lucky. From observation keystrokes sent to a
legacy application are being fired off before the Windows Application is
fully open. You need to waste some time to get just what you want into the
legacy application. You talk about ugly here are my time wasters that make
this technique work.

Time waster number 1 – a do nothing loop

Dim wwait as long

AppActivate “Myappâ€, true
For wwait = 1 to 10000000 ‘here you need to experiment in time.
‘On a 1 Gig machine this is a fairly short amount of time.
on a 1G machine this is not much time
Next wwait
Sendkeys “My typed dataâ€, true

Time waster number 2 – send a bunch of do nothing keystroke many times

AppActivate “Myappâ€, true
‘Home 500 can take some time but if the application clips some
‘so what. It puts the cursor often in the front of the field.
‘+{end} is a keystroke way of selecting the entire contents.
‘you may have bad data there.
..Sendkwys “{home 500}+{end}What you want{tab}â€, true


Time waster number 3 – carefully use the ‘on timer’ property and timer
intervals

You can set up timers on a Form. Ttime is a text box with an unbound control.

Private Sub Eend_Click() ‘Code to stop a form’s timers. Code under a macro
button.
Me.TTime = 0
Me.TimerInterval = 0
End Sub

Private Sub Sstart_Click() ‘Code that starts the time under a macro button.
Me.TTime = 0
Me.TimerInterval = 1000 ‘By definition 1000 = 1 second. 60000 would be
1 minute.

End Sub


Private Sub Form_Timer() ‘This is a standard Access Form Property.
‘This code executes every time the timer interval is reached.
‘In this example one or more seconds is delayed between SendKeys.
If Me.TTime = 1 Then
AppActivate "Telnet", True
ElseIf Me.TTime = 2 Then

SendKeys ";235~", True
ElseIf Me.TTime = 3 Then
SendKeys "{tab 4}" & Left(Me.FIRST_NAME, 10) & "{tab 10}" &
Mid(Me.LAST_NAME, 1, 6) & "{tab}", True
ElseIf Me.TTime = 13 Then
SendKeys "M ~", True
ElseIf Me.TTime > 16 Then
Me.TTime = 0 ‘this sets up the code to execute it over and over
again. 0 to 16 a ‘timing loop
End if
Me.TTime = Me.TTime +1 ‘Each time the timer cycles my unbound control
named Ttime is incremented by 1. In this case 1 second.

My problem is with AppActivate in Access 2003 is that Windows Task Manager
is sometimes showing two instances of the same application with different
names. For example,

AppActivate “Microsoft Excel – Book1â€, true
AppActivate “Book1â€, true

When you get this presentation your AppAcivate may become erratic. I have
not noticed this with legacy application in Windows XP. The example of the
telnet application above did not work in Windows XP, because Microsoft
substituted a new non-Windows standard Telnet application version
5.1.2600.1106 . The keystroke command requires me to navigate the top line
menu by keystrokes. Without a top line menu I could not copy the information
out. The older version of Telnet.exe version 5.0.1717.1 still works in
Windows XP. If your legacy system requires Telent copy the Telnet.exe to your
network and run it directly.

I’ve made a living for 7 years taming lousy and unfriendly legacy
applications with these techniques. What do you do when you have millions of
records in some proprietary Oracle application, for example? No SQL or table
access and one record at a time lousy research and lousy entry. This is the
first time I’ve let my secret outside of my own organization. Don’t tell too
many people. If you can do it once you can do it a million time. There are
some Windows applications written so badly that you can’t use keystrokes to
navigate. Some require mouse clicks. Secret Recorder.exe from Windows 3.1 can
sometimes work. Now recorder macro’s are extremely ugly, and slow. You can
call such a macro by keystrokes like “^{F16}†from Access Sendkeys. It better
be real important for you to go through this headache.

SendKeys Statement


Sends one or more keystrokes to the active window as if typed at the keyboard.

Syntax

SendKeys string[, wait]

The SendKeys statement syntax has these named arguments:

Part Description
string Required. String expression specifying the keystrokes to send.
Wait Optional. Boolean value specifying the wait mode. If False (default),
control is returned to the procedure immediately after the keys are sent. If
True, keystrokes must be processed before control is returned to the
procedure.



Remarks

Each key is represented by one or more characters. To specify a single
keyboard character, use the character itself. For example, to represent the
letter A, use "A" for string. To represent more than one character, append
each additional character to the one preceding it. To represent the letters
A, B, and C, use "ABC" for string.

The plus sign (+), caret (^), percent sign (%), tilde (~), and parentheses (
) have special meanings to SendKeys. To specify one of these characters,
enclose it within braces ({}). For example, to specify the plus sign, use
{+}. Brackets ([ ]) have no special meaning to SendKeys, but you must enclose
them in braces. In other applications, brackets do have a special meaning
that may be significant when dynamic data exchange (DDE) occurs. To specify
brace characters, use {{} and {}}.

To specify characters that aren't displayed when you press a key, such as
ENTER or TAB, and keys that represent actions rather than characters, use the
codes shown below:

Key Code
BACKSPACE {BACKSPACE}, {BS}, or {BKSP}
BREAK {BREAK}
CAPS LOCK {CAPSLOCK}
DEL or DELETE {DELETE} or {DEL}
DOWN ARROW {DOWN}
END {END}
ENTER {ENTER}or ~
ESC {ESC}
HELP {HELP}
HOME {HOME}
INS or INSERT {INSERT} or {INS}
LEFT ARROW {LEFT}
NUM LOCK {NUMLOCK}
PAGE DOWN {PGDN}
PAGE UP {PGUP}
PRINT SCREEN {PRTSC}
RIGHT ARROW {RIGHT}
SCROLL LOCK {SCROLLLOCK}
TAB {TAB}
UP ARROW {UP}
F1 {F1}
F2 {F2}
F3 {F3}
F4 {F4}
F5 {F5}
F6 {F6}
F7 {F7}
F8 {F8}
F9 {F9}
F10 {F10}
F11 {F11}
F12 {F12}
F13 {F13}
F14 {F14}
F15 {F15}
F16 {F16}



To specify keys combined with any combination of the SHIFT, CTRL, and ALT
keys, precede the key code with one or more of the following codes:

Key Code
SHIFT +
CTRL ^
ALT %



To specify that any combination of SHIFT, CTRL, and ALT should be held down
while several other keys are pressed, enclose the code for those keys in
parentheses. For example, to specify to hold down SHIFT while E and C are
pressed, use "+(EC)". To specify to hold down SHIFT while E is pressed,
followed by C without SHIFT, use "+EC".

To specify repeating keys, use the form {key number}. You must put a space
between key and number. For example, {LEFT 42} means press the LEFT ARROW key
42 times; {h 10} means press H 10 times.

Note You can't use SendKeys to send keystrokes to an application that is
not designed to run in Microsoft Windows or Macintosh. Sendkeys also can't
send the PRINT SCREEN key {PRTSC} to any application.



AppActivate Statement Example’ From Microsoft
This example illustrates various uses of the AppActivate statement to
activate an application window. The Shell statements assume the applications
are in the paths specified. On the Macintosh, the default drive name is "HD"
and portions of the pathname are separated by colons instead of backslashes.

Dim MyAppID, ReturnValue
AppActivate "Microsoft Word" ' Activate Microsoft
' Word.

' AppActivate can also use the return value of the Shell function.
MyAppID = Shell("C:\WORD\WINWORD.EXE", 1) ' Run Microsoft Word.
AppActivate MyAppID ' Activate Microsoft
' Word.



' You can also use the return value of the Shell function.
ReturnValue = Shell("c:\EXCEL\EXCEL.EXE",1) ' Run Microsoft Excel.
AppActivate ReturnValue ' Activate Microsoft
' Excel.

TimerInterval Property
See AlsoApplies ToExampleSpecificsYou can use the TimerInterval property to
specify the interval, in milliseconds, between Timer events on a form.
Read/write Long.

expression.TimerInterval
expression Required. An expression that returns one of the objects in the
Applies To list.

Remarks
The TimerInterval property setting is a Long Integer value between 0 and
2,147,483,647.

You can set this property by using the form's property sheet, a macro, or
Visual Basic.


Note When using Visual Basic, you set the TimerInterval property in the
form's Load event.


To run Visual Basic code at intervals specified by the TimerInterval
property, put the code in the form's Timer event procedure. For example, to
requery records every 30 seconds, put the code to requery the records in the
form's Timer event procedure, and then set the TimerInterval property to
30000.

Example
The following example shows how to create a flashing button on a form by
displaying and hiding an icon on the button. The form's Load event procedure
sets the form's TimerInterval property to 1000 so the icon display is toggled
once every second.

Sub Form_Load()
Me.TimerInterval = 1000
End Sub

Sub Form_Timer()
Static intShowPicture As Integer
If intShowPicture Then
' Show icon.
Me!btnPicture.Picture = "C:\Icons\Flash.ico"
Else
' Don't show icon.
Me!btnPicture.Picture = ""
End If
intShowPicture = Not intShowPicture
End Sub
 
Back
Top