Link to home
Start Free TrialLog in
Avatar of BFanguy
BFanguyFlag 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
DoEvents
End If

Looking for an alternate method.

Thanks in advance.
Avatar of BFanguy
BFanguy
Flag of United States of America image

ASKER

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)
Avatar of 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 ?
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Do you want to select the text in the field?
Avatar of BFanguy

ASKER

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