SendKeys randomly not working

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

Guest

I have a database that uses SendKeys for a number of functions. They have
always worked fine.
Recently all the SendKey functions have been behaving strangely. Typically
they will work the first one or two times they are used and then stop
working. No error messages - just no sending keystrokes. If you restart
the database the chances are the functions will work again for a while.
There have been no obvious changes and the same code seems to work without
incident on other users machines.
Any ideas? Thanks
 
hi pricey,
Recently all the SendKey functions have been behaving strangely. Typically
they will work the first one or two times they are used and then stop
working. No error messages - just no sending keystrokes.
SendKeys is a beast. It works, but you can never be sure which window
gets the key messages.

Use explicit SetFocus before using SendKeys.

btw, can you give us some examples of your SendKeys code?


mfG
--> stefan <--
 
Thanks Stefan

Here's one simple example - but there are many others. It gets the right
window - but just doesn't send the keystrokes sometimes.

Public Function DateStamp(StampControlName As Variant) As Integer

On Error GoTo DateTimeStamp_Err
DoCmd.GoToControl StampControlName
SendKeys "{F2}^{Home}^{Enter}^{Enter}^{Home}" & Format$(Now, "dddd mmmm
d, yyyy hh:nn AM/PM") & " - " & Forms!settings!user.Column(1) & "^{Enter}"

DateTimeStamp_Exit:
Exit Function

DateTimeStamp_Err:
MsgBox "Error:" + Error$
Resume DateTimeStamp_Exit

End Function
 
SendKeys is seldom recommended.

What exactly is that supposed to be doing? Where is focus supposed to be
after "{F2}^{Home}^{Enter}^{Enter}^{Home}": a textbox in the application, or
a textbox in some other application. If it's the same application, you
should be able to set the value of the textbox without needing to use
SendKeys.
 
Thanks Doug. That particular example is on the same form.

I agree SendKeys is a v unelegant way of getting this (and other jobs) done.
However in this database there are dozens of different uses of it and I'd
rather not redo them all unless I have to.

It is the random thing I don't get. It has been working fine for years -
suddenly it's become tempramental.
 
Sorry, but you should redo them all.

SendKeys should only be used as an absolute last resort, due to its
fickleness. I'd say you've been lucky if you'd been using it for years.
 
I think I read somewhere that SendKeys used in an Access 2003 or earlier
database will not work properly in Access 2007. MS moved around all the menus
and things. If you are thinking about installing A07, you might want to get
started in replacing the SendKey code now.
 
Back
Top