Place cursor in a control and have exisiting text highlighted, ready to replace

K

Karen

That's a long subject line, isn't it...

Anyway, I have a form (continuous records) that uses an unbound control
(entercode) with a AfterUpdate event to trigger a query. So the user
enters an item number in entercode and when the Enter key is pressed
the code gets done. The code is Me.Requery and entercode.setfocus.
The form displays the code and description in the header and then the
location, picksequence, qty on hand etc in the detail section. There
may be multiple locations for a code.

I want to have the cursor return to the entercode control and have the
text there be highlighted and ready to be replaced when the user starts
typing another code. I was able to do this by using the Navigation
Buttons to go to last record and then go to first record. So I tried
doing this in the code using

docmd.gotorecord acdataform, "frm Item View", aclast

that works great unless the code entered has the same number of
locations as the previous code. when that happens the cursor returns
to the entercode control but the text isn't highlighted and the user
has to delete the old code before entering a new code.

Any ideas of how I can make this work?

Thanks in advance,
Karen
 
B

Barry Gilbert

Instead of navigating records, try something like this:

Me.txtEnterCode.SetFocus
Me.txtEnterCode=""

Barry
 
K

Karen

Barry said:
Instead of navigating records, try something like this:

Me.txtEnterCode.SetFocus
Me.txtEnterCode=""

Barry
Well...
that's okay except the users won't see the code they entered while they
look at the details of the code.
Next idea?

K-
 
B

Barry Gilbert

If you just use SetFocus (the first line of my suggestion), it should put the
cursor there and highlight the text. If it doesn't do this, go to Tools,
Options, Keyboard tab. If you set the "Behavior After Entering Field" value
to "Select Entire Field", it should select the entire value.

Barry
 
K

Karen

Barry said:
If you just use SetFocus (the first line of my suggestion), it should put the
cursor there and highlight the text. If it doesn't do this, go to Tools,
Options, Keyboard tab. If you set the "Behavior After Entering Field" value
to "Select Entire Field", it should select the entire value.

Barry
I got it working with the following in the code

me.requery
docmd.gotorecord ....
entercode.setfocus

and then in the Tools, options, keyboard; Move after enter = Don't Move
and Behavior After Entering Field = Select Entire Field.

I needed the gotorecord so that I could get an 'Item Not found' message
to appear when necessary.

Thanks for your help.
K-
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top