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