Using keyboard shortcut

  • Thread starter Thread starter Toni
  • Start date Start date
T

Toni

I have a form with a memo field for a report to be written
in. I also have a button on the form which will add
the 'persons' name to the form to save typing it. The
code also re-positions the cursor at the end of the text
to allow continuation of typing. The code is this:
--------------------------------------------------
Private Sub cmdGirlsName_Click()

Comments.SetFocus
Comments.Text = (Comments.Text & " " & girlsName)
SendKeys "^{END}", True

End Sub
--------------------------------------------------
This works great when the button is clicked. I also have
a keyboard shortcut, alt+g, which I set using & in the
button's caption. When you use alt+g the cursor is not
position at the end of the text but at the beginning of
the text (which is the default). Does anybody know
another way I can code this so it works when the button is
clicked and also when the shortcut is used?

Is it something to do with the button having control
during the code running, and then returns control to the
memo box, which then positions the cursor according to the
default?

Many thanks for any help.

Toni
 
Hi Toni,

It is best to avoid using SendKeys - for most tasks there is a better way.
The problem with Sendkeys is that there is no guarantee which application
will get the sent keystrokes - you could encounter some strange issues in
other applications. Here is a better solution:

Comments.SetFocus
Comments.Text = (Comments.Text & " " & girlsName)
me.comments.selstart = len(me.comments)
 
Sandra, that works brilliantly, you can access the code by
clicking the button, using the shortcut or even tab and
enter and the cursor is at the end of the text. Thanks a
bunch, if you get a spare minute could you explain to me
what the code is?

Toni.
-----Original Message-----
Hi Toni,

It is best to avoid using SendKeys - for most tasks there is a better way.
The problem with Sendkeys is that there is no guarantee which application
will get the sent keystrokes - you could encounter some strange issues in
other applications. Here is a better solution:

Comments.SetFocus
Comments.Text = (Comments.Text & " " & girlsName)
me.comments.selstart = len(me.comments)

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

I have a form with a memo field for a report to be written
in. I also have a button on the form which will add
the 'persons' name to the form to save typing it. The
code also re-positions the cursor at the end of the text
to allow continuation of typing. The code is this:
--------------------------------------------------
Private Sub cmdGirlsName_Click()

Comments.SetFocus
Comments.Text = (Comments.Text & " " & girlsName)
SendKeys "^{END}", True

End Sub
--------------------------------------------------
This works great when the button is clicked. I also have
a keyboard shortcut, alt+g, which I set using & in the
button's caption. When you use alt+g the cursor is not
position at the end of the text but at the beginning of
the text (which is the default). Does anybody know
another way I can code this so it works when the button is
clicked and also when the shortcut is used?

Is it something to do with the button having control
during the code running, and then returns control to the
memo box, which then positions the cursor according to the
default?

Many thanks for any help.

Toni

.
 
Hi Toni,

In a nutshell it just says put the cursor (SelStart) at the last postion of
the existing text (len=length). Glad it's working for you!

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.


Sandra, that works brilliantly, you can access the code by
clicking the button, using the shortcut or even tab and
enter and the cursor is at the end of the text. Thanks a
bunch, if you get a spare minute could you explain to me
what the code is?

Toni.
-----Original Message-----
Hi Toni,

It is best to avoid using SendKeys - for most tasks there is a
better way. The problem with Sendkeys is that there is no guarantee
which application will get the sent keystrokes - you could encounter
some strange issues in other applications. Here is a better solution:

Comments.SetFocus
Comments.Text = (Comments.Text & " " & girlsName)
me.comments.selstart = len(me.comments)

--
Sandra Daigle
[Microsoft Access MVP]
For the benefit of others please post all replies to this newsgroup.

I have a form with a memo field for a report to be written
in. I also have a button on the form which will add
the 'persons' name to the form to save typing it. The
code also re-positions the cursor at the end of the text
to allow continuation of typing. The code is this:
--------------------------------------------------
Private Sub cmdGirlsName_Click()

Comments.SetFocus
Comments.Text = (Comments.Text & " " & girlsName)
SendKeys "^{END}", True

End Sub
--------------------------------------------------
This works great when the button is clicked. I also have
a keyboard shortcut, alt+g, which I set using & in the
button's caption. When you use alt+g the cursor is not
position at the end of the text but at the beginning of
the text (which is the default). Does anybody know
another way I can code this so it works when the button is
clicked and also when the shortcut is used?

Is it something to do with the button having control
during the code running, and then returns control to the
memo box, which then positions the cursor according to the
default?

Many thanks for any help.

Toni

.
 
Back
Top