Object name on user form
You could select the text and hit ctrl-c, then select the other textbox and hit
ctrl-v to paste.
No VBA required.
But I still have my little userform with 5 sending textboxes, 2 receiving
textboxes and 2 commandbuttons and this worked ok:
Option Explicit
Dim FromTextbox As MSForms.TextBox
Private Sub CommandButton1_Click()
Set FromTextbox = Me.ActiveControl
End Sub
Private Sub CommandButton2_Click()
If FromTextbox Is Nothing Then
Beep
Else
Me.ActiveControl.Value = FromTextbox.Value
End If
End Sub
Private Sub TextBox1_Enter()
Set FromTextbox = Me.TextBox1
Call EnableButtons(FromOrToOrAll:="FromOk")
End Sub
Private Sub TextBox2_Enter()
Set FromTextbox = Me.TextBox1
Call EnableButtons(FromOrToOrAll:="FromOk")
End Sub
Private Sub TextBox3_Enter()
Set FromTextbox = Me.TextBox1
Call EnableButtons(FromOrToOrAll:="FromOk")
End Sub
Private Sub TextBox4_Enter()
Set FromTextbox = Me.TextBox1
Call EnableButtons(FromOrToOrAll:="FromOk")
End Sub
Private Sub TextBox5_Enter()
Set FromTextbox = Me.TextBox1
Call EnableButtons(FromOrToOrAll:="FromOk")
End Sub
Private Sub TextBox6_Enter()
If FromTextbox Is Nothing Then
Call EnableButtons(FromOrToOrAll:="noenabled")
Else
Call EnableButtons(FromOrToOrAll:="ToOk")
End If
End Sub
Private Sub TextBox7_Enter()
If FromTextbox Is Nothing Then
Call EnableButtons(FromOrToOrAll:="noenabled")
Else
Call EnableButtons(FromOrToOrAll:="ToOk")
End If
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(FromOrToOrAll:="noenabled")
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(FromOrToOrAll:="noenabled")
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(FromOrToOrAll:="noenabled")
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(FromOrToOrAll:="noenabled")
End Sub
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(FromOrToOrAll:="noenabled")
End Sub
Private Sub TextBox6_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(FromOrToOrAll:="noenabled")
End Sub
Private Sub TextBox7_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(FromOrToOrAll:="noenabled")
End Sub
Private Sub EnableButtons(FromOrToOrAll As String)
Me.CommandButton1.Enabled = False
Me.CommandButton2.Enabled = False
Select Case LCase(FromOrToOrAll)
Case Is = "noenabled"
'leave them disabled
Case Is = "fromok"
Me.CommandButton1.Enabled = True
Case Else
Me.CommandButton2.Enabled = True
End Select
End Sub
Private Sub UserForm_Initialize()
With Me.CommandButton1
.Caption = "Copy Text"
.Enabled = False
.TakeFocusOnClick = False
End With
With Me.CommandButton2
.Caption = "Paste Text"
.Enabled = False
.TakeFocusOnClick = False
End With
Me.TextBox1.SetFocus
Set FromTextbox = Nothing
End Sub
Alan wrote:
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
--
Dave Peterson
|