syntax to copy text string from another field to clipboard

T

tstew

Hello,

The following code gets me close, but not quite. When this runs, I get an
error that the field doesn't exist. It's reading the text in the field as if
it's a field name. I'm just trying to copy the text string from Pic_Location
to the clipboard when I enter an unbound text box so it's ready to insert
into the next chosen record. The code is:
******************************************
Private Sub txtFilterAddress_Enter()

If Not IsNull(Me.Pic_Location) And Not (Me.Pic_Location) = "JL No Pic"
And Not (Me.Pic_Location) = "no pic" Then
DoCmd.GoToControl (Pic_Location)
DoCmd.RunCommand acCmdCopy
End If

End Sub
*******************************************
My reasoning for triggering the event on enter of the text box is that is
the last action performed on this record before selecting the next record.

Any ideas?

Thanks,
Mark
 
T

Tom van Stiphout

On Sat, 7 Nov 2009 15:46:04 -0800, tstew

DoCmd.GoToControl expects a control name; you gave it a control.
Rewrite it as:
DoCmd.GoToControl :)Pic_Location")
or
DoCmd.GoToControl (Me.Pic_Location.Name)

-Tom.
Microsoft Access MVP
 
L

Linq Adams via AccessMonster.com

I think that after moving to the control, you also need to select the text
before attempting to copy it:

Me.Pic_Location.SelStart = 0
Me.Pic_Location.SelLength = Len(Me.Pic_Location)
DoCmd.RunCommand acCmdCopy
 
L

Linq Adams via AccessMonster.com

I just noticed that Tom's finger apparently slipped with this:

DoCmd.GoToControl :)Pic_Location")

I'm sure he meant

DoCmd.GoToControl ("Pic_Location")

Probaly had fried chicken for Sunday dinner!

;0)>
 
J

John_G via AccessMonster.com

Hi -

Instead of using the clipboard, why not use a variable accessible by all sub-
programs in the form module?

e.g. at the top of the module put:

Dim txtTempVar as String

and then all you need is

Private Sub txtFilterAddress_Enter()
txtTempVar = "" 'Clear any existing value
If Not IsNull(Me.Pic_Location) And Not (Me.Pic_Location) = "JL No Pic"
And Not (Me.Pic_Location) = "no pic" Then
txtTempVar = me!Pic_Location
End If

End Sub

Then all you need to do later is me!SomeField = txtTempVar

This has the advantage that you can use the clipboard for other purposes.

John
 
T

ThriftyFinanceGirl

Could it be that you are not referring to your field with the "ME...." in
front? It might not be able to find it without the designator in front.
 

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