View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Rick Rothstein \(MVP - VB\)[_1339_] Rick Rothstein \(MVP - VB\)[_1339_] is offline
external usenet poster
 
Posts: 1
Default How to refer to the .text property without text box name?

From inside an event procedure for any control, you could refer to that
control via the ActiveControl object (since, in order for the event
procedure of a control to be running, that control must be the active
control). So, for your example Change event for, say, txtNew1...

Sub txtNew1_Change()
....some statement
ActiveControl.Text
....some statement
End sub

Although, if you are in an event procedure, it must be for a particular
control which you know the name of, so using an indirection through the
ActiveControl doesn't really gain anything over just using the control name
itself within its own event procedure. The real benefit of ActiveControl
would be in a common Sub or Function called from several similar controls'
event procedure so that the Sub or Function could figure out which control
it was executing its code for. So, in the two code samples you posted, if
all the "some statements" were identical, except for the control they were
being executed for, putting those statements in a Sub, and having each of
those Change event procedures call that Sub (which in turn used the
ActiveControl to figure out which control's Change event called it), would
be a more logical use of ActiveControl.

Rick


"Yajiv" wrote in message
...
I have a textbox called txtNew.
How can i use the .text property without actually typing txtNew.text?
I dont want to use "with" statement. is there any way to refer like
"this.text"?
(so that i can use those statements for all the textboxes, if
necessary)

Sub txtNew_Change
...some statement
this.text
...some statement
End sub

sub txtNew1_Change
...some statement
this.text
...some statement
End sub