Need help with Sendkeys

P

Paul Fenton

We have a customers form that we open to view various records. When
we open the form, I set the focus to the Last Name field. When I do
that, the name is highlighted and if someone does CTRL-F to find,
whatever name is highlighted shows up in the "Find What" field of the
Find and Replace form.

So I put this line in the OnCurrent event:

Sendkeys "{F2}"

which leaves the cursor in the Last Name field, at the end of the name
in the field and solves the Find problem.

What I can't figure out is where to put that Sendkeys line when the
form is opened for the first time. I've tried OnOpen and Activate but
it it still highlights that full name.

What am I doing wrong?


Paul Fenton
 
R

Rick Brandt

Paul said:
We have a customers form that we open to view various records. When
we open the form, I set the focus to the Last Name field. When I do
that, the name is highlighted and if someone does CTRL-F to find,
whatever name is highlighted shows up in the "Find What" field of the
Find and Replace form.

So I put this line in the OnCurrent event:

Sendkeys "{F2}"

which leaves the cursor in the Last Name field, at the end of the name
in the field and solves the Find problem.

What I can't figure out is where to put that Sendkeys line when the
form is opened for the first time. I've tried OnOpen and Activate but
it it still highlights that full name.

What am I doing wrong?


Paul Fenton

Don't use SendKeys. Check help for SelStart and SelLength properties.
 
T

tshillam

We have a customers form that we open to view various records. When
we open the form, I set the focus to the Last Name field. When I do
that, the name is highlighted and if someone does CTRL-F to find,
whatever name is highlighted shows up in the "Find What" field of the
Find and Replace form.

So I put this line in the OnCurrent event:

Sendkeys "{F2}"

which leaves the cursor in the Last Name field, at the end of the name
in the field and solves the Find problem.

What I can't figure out is where to put that Sendkeys line when the
form is opened for the first time. I've tried OnOpen and Activate but
it it still highlights that full name.

What am I doing wrong?

Paul Fenton

Try two different SendKeys() commands on your OnOpen event. Try
sending a right arrow (places the cursor at the end of the name), then
your F2 on your OnOpen event.
 
S

Stephen Lebans

Do not use SendKeys for this. In the Current event, SetFocus to the desired
control and set the SelStart property to place the cursor wherever you need
to.

For the first time the form loads, Use the Form's Load event and follow the
same logic as outlined above.

--

HTH
Stephen Lebans
http://www.lebans.com
Access Code, Tips and Tricks
Please respond only to the newsgroups so everyone can benefit.
 
P

Paul Fenton

Thanks to all who responded. Took your advice and use the SelStart
property instead of SendKeys. Works like a charm.


Paul Fenton
 

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