SendKeys randomly not working

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
 
S

Stefan Hoffmann

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 <--
 
G

Guest

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
 
D

Douglas J. Steele

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.
 
G

Guest

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.
 
D

Douglas J. Steele

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top