Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Me

Status
Not open for further replies.

OOzy

Programmer
Jul 24, 2000
135
0
0
SA
Hi

To reference form we use Me. If I want to reference a textbox in that for without using its name, what should I do.

For example, if the form name is frmTest. I could do this

FrmText.Top=555

Or

Me.Top = 555

If my textbox is txtTest what should I do to ref w/o using

TxtText.Top=555
 
You could use Me.ActiveControl, which returns a reference to the active control on a form, funnily enough.

You can see if its a text box by doing something like

If TypeName(Me.ActiveControl) = "TextBox" Then
Me.ActiveControl.Top = ...

or

If Left(LCase(Me.ActiveControl.Name), 3) = "txt" Then...
 
Actually,
Code:
Me
refers to the current instance of a class. In "code behind form", this is the current instance of the form. If you want to use the
Code:
Me
keyword because you want the same code for many text boxes, you can write a so called 'wrapper class':

Code:
'start of a new class module, say clsTextBoxWrap
private withevents txtWrapped as textbox

public sub construct(byref txt as textbox)
 set txtWrapped = txt
end sub

private sub class_terminate()
 set txtWrapped = Nothing
end sub

'you can write event procedures or methods in this class
'Do not use the Me keyword to refer to the textbox, but
'just txtWrapped
'Then, in the form's initialization code, put
'something like:
'private mtxtWhatever as new clsTextBoxWrap (at module level)
'...
'mtxtWhatEver.construct ... (in the initialization)
'and do that for all the textboxes you want to share
'the same behaviour

Hope this helps
 
You can reference a control without using it's name repeatedly using "With" e.g.

Code:
With txtTest

    .Top = 555

    .Left = 200

    .Text = ""

End With 'txtTest

Daren
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top