[AccessD] Set control to 'edit' in VBA?

Dan Waters dwaters at usinternet.com
Fri Apr 22 18:19:55 CDT 2005


Penn,

You can make a global change by going to Tools|Options, selecting the
Keyboard tab, and making the appropriate choice under Behavior Entering
Field.

To select all the text in a field regardless of the choice from above you
can do this in the field's Enter event:

    txtPhoneNumber.SelStart = 0
    txtPhoneNumber.SelLength = Len(txtPhoneNumber)


HTH,
Dan Waters


-----Original Message-----
From: accessd-bounces at databaseadvisors.com
[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of Penn White
Sent: Friday, April 22, 2005 4:54 PM
To: Access Developers discussion and problem solving
Subject: [AccessD] Set control to 'edit' in VBA?

Does anyone know of a way to send a user back to a control and have it 
already be in Edit Mode (F2) when they get there?

I can send the user back using Me!MyControl.SetFocus but then the field is 
entirely highlighted and if they type anything before hitting F2 then the 
entire highlighted data will be replaced by the new character(s).

I'm using it in a custom validation routine for phone numbers.  If they type

in an incorrect number of numbers or start with a '1' or enter illegal alpha

or extended characters, it pops up a message telling them to try again. 
Before checking the number for length, all the extraneous characters (like 
( or ) or - or " ") are stripped and then if it is a valid 10 character 
integer, it is reformatted to a standard format.  This is done in the OnExit

event because sometimes the phone numbers are cut and pasted from somewhere 
else and this does not trigger the AfterUpdate event.  There may be a better

way to do this but this is the one I've come up with so far.

I believe I saw somewhere that there is a way to do this globally for the 
entire database but I'd rather just have it apply as I need it.  Generally, 
I find it's good to have everything highlighted when you enter a control.

Thank you,

Penn 
-- 
AccessD mailing list
AccessD at databaseadvisors.com
http://databaseadvisors.com/mailman/listinfo/accessd
Website: http://www.databaseadvisors.com




More information about the AccessD mailing list