View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Object name on user form

Peter, even a text box that contains a text string is returning the
value 'False' in response to Me.ActiveControl - am I missing
something?


I was slightly wrong, when a textbox contains a string its default property
returns False. But that's not the point and yes you are missing something, I
had hoped the little demo I posted would have illustrated - did you try it?

When you click a button the textbox is no longer the "ActiveControl". But
there are ways round that, here's one approach for what you describe as the
objective -

Put all your textboxes "in" a frame. Put a frame on your form named Frame1,
select all your textboxes and "cut", select the frame and "paste" into the
frame. Do not put any other controls in the frame, at least not your
copy/paste buttons. (You can clear the frame's caption and format the border
to make the frame invisible if/as desired.

Put two buttons of the form named CommandButton1 & 2 (captions "copy" &
"paste")

Dim mCtrl As Object

Private Sub CommandButton1_Click()
CopyPaste False
End Sub

Private Sub CommandButton2_Click()
CopyPaste True
End Sub

Sub CopyPaste(bPaste As Boolean)
Dim sMsg As String
Dim obj As Object

Set obj = Me.Frame1.ActiveControl
If TypeName(obj) = "TextBox" Then
If bPaste Then
If mCtrl Is Nothing Then
MsgBox "First select text box and press copy button"
Else
obj.Text = mCtrl.Text
Set mCtrl = Nothing ' in effect clear clipbaord
End If
Else
Set mCtrl = obj
End If
Else
MsgBox "select the textbox you want to " & _
IIf(bPaste, "paste to", "copy from")
End If

End Sub

As written user can change text after copying but before pasting. If that's
not desired store text in the the source textbox to a module level string
variable instead (of storing a reference to the textbox).

You might want to include a few more info messages.

Regards,
Peter T

"Alan" wrote in message
...
Thanks for your input here guys but I really am still struggling - I'm
sure that it is just me trying to describe what I am after!

The process that I am trying to emulate is:

1: user places cursor in one of the text boxes and presses a 'copy
button' - this could either store the value in a variable that could
then be used to 'paste' to another location or set the selected text
box as an object that could be referred to in the 'paste' step.

2: user places cursor in another text box and presses a 'paste button'
- this could either cause the value of the variable to be written to
that location or if the previous location has been stored as an object
I could proceed along the lines of textbox2.value=textbox1.value

The above preceedure is totally independant of how many text boxes
there are in total.

Peter T wrote "Me.ActiveControl on its own returns the default
property of the control that
currently has focus, which for most controls is typically False
(unless it
has a 'Value' property = true). Though controls such as Textbox, which
have
no default property, return an empty string. "

Peter, even a text box that contains a text string is returning the
value 'False' in response to Me.ActiveControl - am I missing
something?

Alan