Need help with Sendkeys

  • Thread starter Thread starter Paul Fenton
  • Start date Start date
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
 
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.
 
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.
 
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.
 
Thanks to all who responded. Took your advice and use the SelStart
property instead of SendKeys. Works like a charm.


Paul Fenton
 
Back
Top