Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / June 2008

Tip: Looking for answers? Try searching our database.

Detecting or reading the name of a textbox

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Sunouchi@ - 28 Jun 2008 16:20 GMT
Hello Everybody

I have two questions:

1.)
In my UserForm I can detect the name of the form, the name of a frame
on that form, but how can I detect (read) the name of a texbox in that
frame?

   str_Form = Me.Name
   str_Frame = Me.ActiveControl.Name
   str_TextBox = (how to do that?)

2.)

How can I detect the name of any textbox whith a mouse click in that
textbox, e.g. with the MouseDown Event?

Tanks in advance,
Hans
Doug Robbins - Word MVP - 28 Jun 2008 23:34 GMT
Do you really need the textbox inside a frame?  If you want to have a group
of textboxes contained within a border, put them inside an empty label to
which you apply a border and then you can use:

Private Sub txtStart_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
MsgBox Me.ActiveControl.Name
End Sub

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

> Hello Everybody
>
[quoted text clipped - 16 lines]
> Tanks in advance,
> Hans
Sunouchi@ - 29 Jun 2008 10:40 GMT
>Do you really need the textbox inside a frame?  If you want to have a group
>of textboxes contained within a border, put them inside an empty label to
[quoted text clipped - 4 lines]
>MsgBox Me.ActiveControl.Name
>End Sub

Thanks for your answer, but a frame is more convenient. I can easily
replace the content at once to another position on the form. This is
difficult with a label.
If I want to move the textboxes within the label, the label will  be
selected as well, wicht makes things difficult.
Besides that, some of the textboxes are created at run time,
dynamically. So, in that case your routine is not applicable, because
at design time the textbox doesn't exist.

From your answer, can  I say that it is impossible to detect the name
of a textbox in a frame?

All the best,
Hans
Doug Robbins - Word MVP - 29 Jun 2008 20:40 GMT
I could not find a way to do it, but that may only mean the method is
elusive, not impossible.

Signature

Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

>>Do you really need the textbox inside a frame?  If you want to have a
>>group
[quoted text clipped - 20 lines]
> All the best,
> Hans
Helmut Weber - 30 Jun 2008 15:34 GMT
Hi Hans,

Doug accesses the active control of the userform,
which is the frame.
You may try to access the activecontrol in the frame, like that:

Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
If Me.ActiveControl.name = "Frame1" Then
  MsgBox Me.Frame1.ActiveControl.name
End If
End Sub

which requires two mouseclicks,
on in the textbox in the frame,
one click outside the frame.


--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
Helmut Weber - 30 Jun 2008 15:38 GMT
Also possible,

Private Sub Frame1_MouseDown(ByVal Button As Integer, ByVal Shift As
Integer, ByVal X As Single, ByVal Y As Single)
MsgBox Me.Frame1.ActiveControl.name
End Sub

which requires a second mouseclick inside the frame
after the cursor was put into a textbox in the frame.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
fumei - 30 Jun 2008 19:49 GMT
How can I detect the name of any textbox whith a mouse click in that textbox,
e.g. with the MouseDown Event?

By using the MouseDown for that textbox.  I am not sure why the others are
using the userform MouseDown.  The code below assumes that TextBox1 is in
Frame1.

Private Sub TextBox1_MouseDown(ByVal Button As Integer, _
  ByVal Shift As Integer, _
  ByVal X As Single, _
  ByVal Y As Single)
 
  Label1.Caption = Me.Frame1.ActiveControl.Name
End Sub

would write the name ("TextBox1") to the Label caption, when you click into
the textbox.

>Hello Everybody
>
[quoted text clipped - 16 lines]
>Tanks in advance,
>Hans
fumei - 30 Jun 2008 19:50 GMT
That is, only one mouse click is required.  You click into the textbox, the
name is written to the label.  One click.

>How can I detect the name of any textbox whith a mouse click in that textbox,
>e.g. with the MouseDown Event?
[quoted text clipped - 19 lines]
>>Tanks in advance,
>>Hans
fumei - 30 Jun 2008 19:55 GMT
Further, I have to agree with the question regarding textboxes in frames.

AND, if you are creating the textboxes (in the frame) dynamically - at run-
time -  then you are indeed stuck.  For you are correct, the MouseDown is not
there.  You could possibkly write it in anyway, and make sure the name is the
nameof the in-the-future textbox.

I also have to say that unless there is areal serious reason for it, I rarely
create controls at run-time.  It is much much easier to make controls
visible/invisble as required.  I do often dynamically resize things, but
things that are already there.

Being already there, but say, resized tiny and invisible, all events for that
control are accessible.

>That is, only one mouse click is required.  You click into the textbox, the
>name is written to the label.  One click.
[quoted text clipped - 4 lines]
>>>Tanks in advance,
>>>Hans
Sunouchi@ - 01 Jul 2008 00:25 GMT
I solved the problem with reading the name and the contents of the
Dynamically created textboxes

fr_Velden is the frame
The names of the textboxes are: 'TextBox' and a number
col_CatalUnicode is a Collection

It works fine. That is what I need: the text in the TextBoxes

For Each ctl_Control In .fr_Velden.Controls
           str_ControlName = ctl_Control.Name
           str_ControlIdent = Left(str_ControlName, 7)
           If str_ControlIdent = "TextBox" Then col_CatalUnicode.Add
Item:=ctl_Control.Text
Next

Thanks for your attention
Hans

>Further, I have to agree with the question regarding textboxes in frames.
>
[quoted text clipped - 19 lines]
>>>>Tanks in advance,
>>>>Hans
Helmut Weber - 30 Jun 2008 20:01 GMT
Hi Fumei,

>By using the MouseDown for that textbox.  I am not sure why the others are
>using the userform MouseDown.

because the code in userform mousedown
would be required only once, just for the form,
otherwise you would need the code for a textbox mousedown
for each textbox.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.