View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Dave Peterson Dave Peterson is offline
external usenet poster
 
Posts: 35,218
Default Object name on user form

You may want to describe how many source textboxes you have and how many
destination textboxes you have.

Say you have 8 source and 2 destinations.

You could have a commandbutton that copies the "active textbox" to the first
destination textbox and another that would copy to the second destionation.

You'd select the sending textbox and then click one of the two buttons. The
buttons would have the .takefocusonclick set to false.

I built a small userform with 7 buttons (I was lazy and didn't know what your
layout was anyway).

There are 5 source textboxes and 2 receiving textboxes (and therefore 2
commandbuttons).

This is the code behind the userform:

Option Explicit
Private Sub CommandButton1_Click()
Me.TextBox6.Value = Me.ActiveControl.Value
End Sub
Private Sub CommandButton2_Click()
Me.TextBox7.Value = Me.ActiveControl.Value
End Sub
Private Sub TextBox1_Enter()
Call EnableButtons(OnOrOff:=True)
End Sub
Private Sub TextBox2_Enter()
Call EnableButtons(OnOrOff:=True)
End Sub
Private Sub TextBox3_Enter()
Call EnableButtons(OnOrOff:=True)
End Sub
Private Sub TextBox4_Enter()
Call EnableButtons(OnOrOff:=True)
End Sub
Private Sub TextBox5_Enter()
Call EnableButtons(OnOrOff:=True)
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(OnOrOff:=False)
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(OnOrOff:=False)
End Sub
Private Sub TextBox3_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(OnOrOff:=False)
End Sub
Private Sub TextBox4_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(OnOrOff:=False)
End Sub
Private Sub TextBox5_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Call EnableButtons(OnOrOff:=False)
End Sub
Private Sub EnableButtons(OnOrOff As Boolean)
Me.CommandButton1.Enabled = OnOrOff
Me.CommandButton2.Enabled = OnOrOff
End Sub
Private Sub UserForm_Initialize()

With Me.CommandButton1
.Caption = "Copy to TB6"
.Enabled = False
.TakeFocusOnClick = False
End With

With Me.CommandButton2
.Caption = "Copy to TB7"
.Enabled = False
.TakeFocusOnClick = False
End With

Me.TextBox1.SetFocus

End Sub


Alan wrote:

Because there are a number of text boxes (10) I don't know where the
user is or where he/she wants to 'paste' to so I can't use the simple

TextBox3.Value = TextBox1.Value

(In answer to Simon, yes, I am trying to make the value stored in the
'paste' box the same as the 'copy' box but only those selected by the
user, not all of them)

Me.ActiveControl.Name returns the name of the selected box but I am
now having trouble using it as the source in a 'paste' command. How
can I turn this text string into an object? - any further ideas please

Me.ActiveControl simply returns the boolean value 'False' and so is
of no use

Alan

On Jan 2, 11:29 am, Mike H wrote:
Hi,

There's no need for copying and pasting use

TextBox3.Value = TextBox1.Value

This line returns the active control name

Me.ActiveControl.Name

nd this retuns the value

Me.ActiveControl

Mike


--

Dave Peterson