sendkeys funny in access VB with runcommand accmdfind

Access 2002 (XP)

I have the following code to try and persuade the find dialog box to start with correct settings using sendkeys. It works (sometimes but also sets caps lock on!
Come on, Bill gates! Any ideas?

"
    ' do the deed
    Me.this.SetFocus             '!!! whatever the first field is for any form
    SendKeys "%ha%e%rd"   ' any part of form and field and looking down, from MS documentation
    Application.RunCommand acCmdFind

"

Thanks.
PeborghAsked:
Who is Participating?
 
harfangCommented:
Hello,

A home-grown "Find"?

    Dim strFind As String
    strFind = InputBox("What now?", "Find")
    If strFind = "" Then Exit Sub
    strFind = Replace(strFind, "'", "''")
    With Me.RecordsetClone
        ' Find first (see below for findnext)
        .FindFirst "YourSearchField Like '*" & strFind & "*'"
        If .NoMatch Then MsgBox "huh?": Exit Sub
        Me.Bookmark = .Bookmark
    End With

Find next:
        .Bookmark = Me.Bookmark
        .FindNext "YourSearchField Like '*" & strFind & "*'"

To have a combination of find first / find next buttons, the best is to store the search criteria in a global variable as a whole:

    gstrCriteria = "YourSearchField Like '*" & strFind & "*'"

Finally, if you feel adventurous, it's quite easy to rewrite the entire "Find" dialog as a custom pop-up form.

Cheers!
(°v°)
0
 
Leigh PurvisDatabase DeveloperCommented:
That's the *classic* bug with Sendkeys.

http://www.mvps.org/access/api/api0046.htm
0
 
PeborghAuthor Commented:
Err...
I pinched the code, incorporated into my app, compiled OK:

"
    ' do the deed
    Me.this.SetFocus                            '!!! whatever the (first) field is for any form
    FsendKeys "%ha%e%rd"                 ' any part of field and going down (uses a "safe" Sendkeys)
    Application.RunCommand acCmdFind

"
... and it behaves just like the original SendKeys, setting caps lock ON.

What am I missing?

Many thanks,

peter
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
Leigh PurvisDatabase DeveloperCommented:
Caps lock wasn't already on?
I assume the API is still valid under XP (was first published some time ago - but would have come to light easily by now otherwise).

I've never used it personally - as I don't use Sendkeys :-)
0
 
PeborghAuthor Commented:
Anyone out there know of an alternative, specifiable find/findNext proc/func?

Thanks.
0
 
PeborghAuthor Commented:
Getting back to the subject in hand, mySendKeys does work!! I was using Fsendkeys and that acted in the uncorrected way. Blame Bill gates.
So thanks to LPurvis for his help on sendkeys and (oVo) for his finding substiture - that knowledge was useful also.

peter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.