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


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Leigh PurvisDatabase DeveloperCommented:
That's the *classic* bug with Sendkeys.
PeborghAuthor Commented:
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,

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 :-)
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

PeborghAuthor Commented:
Anyone out there know of an alternative, specifiable find/findNext proc/func?


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.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.