Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Object name on user form

I have a user form that contains a number of text boxes. I want to
copy the text from one box and paste it to another but to be able to
do that I need to be able to read in the name of the active text box.
How can I do that or is there an easier way to copy/paste?

Regards,
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Object name on user form


What are you trying to achieve?, are you trying to simply enter details
in one textbox and populate the rest with the same?, wouldn't you be
better off actually using the names of the textbox e.g.
Code:
--------------------
Me.Textbox1.value =Me.Textbox2.value
--------------------
Alan;165232 Wrote:
I have a user form that contains a number of text boxes. I want to
copy the text from one box and paste it to another but to be able to
do that I need to be able to read in the name of the active text box.
How can I do that or is there an easier way to copy/paste?

Regards,



--
Simon Lloyd

Regards,
Simon Lloyd
'The Code Cage' (http://www.thecodecage.com)
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.thecodecage.com/forumz/member.php?userid=1
View this thread: http://www.thecodecage.com/forumz/sh...ad.php?t=45854

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,501
Default Object name on user form

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

"Alan" wrote:

I have a user form that contains a number of text boxes. I want to
copy the text from one box and paste it to another but to be able to
do that I need to be able to read in the name of the active text box.
How can I do that or is there an easier way to copy/paste?

Regards,

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Object name on user form

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Object name on user form

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.

Based on user's actions you need to define source and destination textboxes
and what action triggers the copy. Eg, user types text into one textbox,
exits it, enters another, then presses a button (but don't do it like
that!).

In the meantime -

Private Sub UserForm_Click()
Dim ctrl As Object
' with cursor in a textbox that contains text click on form
Set ctrl = Me.ActiveControl
If TypeName(ctrl) = "TextBox" Then
MsgBox ctrl.Text, , ctrl.Name
Else
MsgBox ctrl.Name
End If
End Sub

Regards,
Peter T

"Alan" wrote in message
...
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





  #6   Report Post  
Posted to microsoft.public.excel.programming
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
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Object name on user form

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
  #8   Report Post  
Posted to microsoft.public.excel.programming
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



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default Object name on user form

Can I just thank you guys for your input and for your time, you have
helped me enormously - Dave has supplied the magic solution - why
didn't I think of that?

Thanks again,

Alan

On 2 Jan, 16:08, Dave Peterson wrote:
You could select the text and hit ctrl-c, then select the other textbox and hit
ctrl-v to paste.

No VBA required.

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Date field in user form & Loading a user form on opening workbook Balan Excel Programming 1 May 24th 08 03:40 PM
User form Object corruption Datasort Excel Programming 3 January 19th 06 07:16 PM
How to: User Form to assign a user defined range to a macro variab TrevTrav Excel Programming 1 March 22nd 05 07:57 PM
User cannot print form object after worksheet sent not as attachment Kevin Mitchell Excel Programming 1 April 20th 04 05:01 AM
Multipage Object on User Form Paul Cheers Excel Programming 2 November 27th 03 11:40 AM


All times are GMT +1. The time now is 05:34 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"