Avatar of BFanguy
Flag for United States of America asked on

Access 2010 Sendkeys Equivalent In VBA, Access 2010

I need VBA code that when a field on a form has focus to Send a F2.

Currently i am using the SendKey (which I know everytime a programmer uses the sendkey function a baby kitten is killed...), but there is a known bug in access 2010 (http://support.microsoft.com/kb/179987) that turns off the num locks and caps locks when using sendkeys.

This is what I am using currently:

If Me.Hardness <> "N/A" And Me.Hardness <> "" Then
SendKeys "{F2}", True
End If

Looking for an alternate method.

Thanks in advance.
Microsoft Access

Avatar of undefined
Last Comment
Hamed Nasr

8/22/2022 - Mon

Maybe I should explain further...  When a user tabs into (or clicks) a field on a form and it has data in the field, i want to automatically send a F2 (to put the field in edit mode and at the end of the current text)
Rey Obrero (Capricorn1)

what do you want to happen if this statement is correct ?

If Me.Hardness <> "N/A" And Me.Hardness <> "" Then

or what do you expect the line  > SendKeys "{F2}", True    to do ?
Rey Obrero (Capricorn1)

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Hamed Nasr

Do you want to select the text in the field?
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes

No thats what access does by default, I just want to put the focus at the end of the field so they can append to the data.  i.e.  the field may have BHN- alrealy in it,  i want them to add a value after BHN-    Ex:  BHN-253

capricorn1's suggestion works me.hardness.selstart=len(me.hardness)+1
Hamed Nasr

want to put the focus at the end of the field
If control text is selected, F2 removes deselects text and sets cursor at end of typed text.
Yes, capricorn1's suggestion does work and produces the same behavior.