How do I move the cursor to the end of the field using VBA Access

J

Julie Aldridge

Hi

I have a combo box and a field on a form. The following code copies the
text in the combo box and pastes it at the end of the field . This enables
text from the combo box to be continually added to the field. The code works
fine in earlier versions of Access but in Access 2007 it replaces the text
that is already there. I have tried Multi-value lists, but these seem to be
set at 'limit to list'.

DoCmd.RunCommand acCmdCopy
DoCmd.GoToControl "NamedOther"
SendKeys "{F2}", True
DoCmd.RunCommand acCmdPaste
SendKeys "/ ", True
 
J

Julie Aldridge

Thanks for that, but I need to continually add to the field from mulitiple
selections within the combo box. ermm.... (I have used 'sendkeys' quite a
bit over the last 10 years and now I've got to re-code it all) !!!!

Marshall Barton said:
Julie said:
I have a combo box and a field on a form. The following code copies the
text in the combo box and pastes it at the end of the field . This enables
text from the combo box to be continually added to the field. The code works
fine in earlier versions of Access but in Access 2007 it replaces the text
that is already there. I have tried Multi-value lists, but these seem to be
set at 'limit to list'.

DoCmd.RunCommand acCmdCopy
DoCmd.GoToControl "NamedOther"
SendKeys "{F2}", True
DoCmd.RunCommand acCmdPaste
SendKeys "/ ", True


You should never have used SendKeys because it has always
had numerous problems. A2007 includes it in the list of
"unsafe" statements and you would have to jump through hoops
to get back to where you were in earlier versions.

Your entire block of code can be done using:

NamedOther = NamedOther & [name of the combo box]
 
J

Julie Aldridge

I'm very observant, so must be lucky!
Thanks for code. It is working now


Marshall Barton said:
Just because you never noticed a problem with SendKey,
either means that you were not very observant or that you
were lucky ;-)

So, yes, you really do need to re-code it all :-(
OTOH, most anything that you were doing with SendKeys can be
done another way that is more reliabe, more efficient and
with fewer lines of code.

Doing multiple "appends" to the end of a text box's value is
just a matter of using the line of code I posted earlier in
the combo box's AfterUpdate event procedure. Every time
something is selected in the combo box, it is appended to
the end of whatever is already in the NamedOther text box.
--
Marsh
MVP [MS Access]


Julie said:
Thanks for that, but I need to continually add to the field from mulitiple
selections within the combo box. ermm.... (I have used 'sendkeys' quite a
bit over the last 10 years and now I've got to re-code it all) !!!!

Marshall Barton said:
Julie Aldridge wrote:
I have a combo box and a field on a form. The following code copies the
text in the combo box and pastes it at the end of the field . This enables
text from the combo box to be continually added to the field. The code works
fine in earlier versions of Access but in Access 2007 it replaces the text
that is already there. I have tried Multi-value lists, but these seem to be
set at 'limit to list'.

DoCmd.RunCommand acCmdCopy
DoCmd.GoToControl "NamedOther"
SendKeys "{F2}", True
DoCmd.RunCommand acCmdPaste
SendKeys "/ ", True


You should never have used SendKeys because it has always
had numerous problems. A2007 includes it in the list of
"unsafe" statements and you would have to jump through hoops
to get back to where you were in earlier versions.

Your entire block of code can be done using:

NamedOther = NamedOther & [name of the combo box]
 
J

Julie Aldridge

Hi, I have another problem where I have used send keys in Access 2007. Hope
you can help again.

I have a combo box which looks-up postcodes.
If 'not in list' then I need to copy the text entered in the combo box, open
another form and paste in a text box.

The code DoCmd.runcommand.accmdcopy will not work in the combo box when not
in the list. Although this code does work when using textboxes. I tried to
use the code you gave me for the earlier problem but looks like the problem
is the combo box 'not in list'.


Hope you can help
Thanks
Julie
 
G

Grimwadec

OK, so this should be useful to me in that on afterupdate in a combo box I
call a function called Cutpaste that contains the code "NamedOther =
NamedOther & [FabricType]", FabricType being the name of a TextBox control in
to which I want the text I selected in a Combo Box pasted at the end of
existing text in the text box, but nothing happens. Obviously I am missing
something re this "NamedOther" aspect.Help please
--
Grimwadec


Julie Aldridge said:
I'm very observant, so must be lucky!
Thanks for code. It is working now


Marshall Barton said:
Just because you never noticed a problem with SendKey,
either means that you were not very observant or that you
were lucky ;-)

So, yes, you really do need to re-code it all :-(
OTOH, most anything that you were doing with SendKeys can be
done another way that is more reliabe, more efficient and
with fewer lines of code.

Doing multiple "appends" to the end of a text box's value is
just a matter of using the line of code I posted earlier in
the combo box's AfterUpdate event procedure. Every time
something is selected in the combo box, it is appended to
the end of whatever is already in the NamedOther text box.
--
Marsh
MVP [MS Access]


Julie said:
Thanks for that, but I need to continually add to the field from mulitiple
selections within the combo box. ermm.... (I have used 'sendkeys' quite a
bit over the last 10 years and now I've got to re-code it all) !!!!

:

Julie Aldridge wrote:
I have a combo box and a field on a form. The following code copies the
text in the combo box and pastes it at the end of the field . This enables
text from the combo box to be continually added to the field. The code works
fine in earlier versions of Access but in Access 2007 it replaces the text
that is already there. I have tried Multi-value lists, but these seem to be
set at 'limit to list'.

DoCmd.RunCommand acCmdCopy
DoCmd.GoToControl "NamedOther"
SendKeys "{F2}", True
DoCmd.RunCommand acCmdPaste
SendKeys "/ ", True


You should never have used SendKeys because it has always
had numerous problems. A2007 includes it in the list of
"unsafe" statements and you would have to jump through hoops
to get back to where you were in earlier versions.

Your entire block of code can be done using:

NamedOther = NamedOther & [name of the combo box]
 
G

Grimwadec

--
Grimwadec

aha - worked it out
Julie Aldridge said:
I'm very observant, so must be lucky!
Thanks for code. It is working now


Marshall Barton said:
Just because you never noticed a problem with SendKey,
either means that you were not very observant or that you
were lucky ;-)

So, yes, you really do need to re-code it all :-(
OTOH, most anything that you were doing with SendKeys can be
done another way that is more reliabe, more efficient and
with fewer lines of code.

Doing multiple "appends" to the end of a text box's value is
just a matter of using the line of code I posted earlier in
the combo box's AfterUpdate event procedure. Every time
something is selected in the combo box, it is appended to
the end of whatever is already in the NamedOther text box.
--
Marsh
MVP [MS Access]


Julie said:
Thanks for that, but I need to continually add to the field from mulitiple
selections within the combo box. ermm.... (I have used 'sendkeys' quite a
bit over the last 10 years and now I've got to re-code it all) !!!!

:

Julie Aldridge wrote:
I have a combo box and a field on a form. The following code copies the
text in the combo box and pastes it at the end of the field . This enables
text from the combo box to be continually added to the field. The code works
fine in earlier versions of Access but in Access 2007 it replaces the text
that is already there. I have tried Multi-value lists, but these seem to be
set at 'limit to list'.

DoCmd.RunCommand acCmdCopy
DoCmd.GoToControl "NamedOther"
SendKeys "{F2}", True
DoCmd.RunCommand acCmdPaste
SendKeys "/ ", True


You should never have used SendKeys because it has always
had numerous problems. A2007 includes it in the list of
"unsafe" statements and you would have to jump through hoops
to get back to where you were in earlier versions.

Your entire block of code can be done using:

NamedOther = NamedOther & [name of the combo box]
 

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