devxlogo

Use an Easier Autohighlight Method

Use an Easier Autohighlight Method

Most of us have a routine we call to autohighlight the entire contents of a textbox when it receives focus. And most of us type the name of the textbox when we pass it to this routine. Instead of typing the control’s name in each GotFocus event, you can use this sub to highlight the currently active textbox on the passed form. Place this code in a module:

 Sub HiLite(frm As Form)	frm.ActiveControl.SelStart = 0	frm.ActiveControl.SelLength = _		Len(frm.ActiveControl.Text)End Sub

Then place this line of code in your textbox control’s GotFocus() event:

 Private Sub Text1_GotFocus()	HiLite MeEnd Sub

Using this code, you can forget about typing your controls’ names over and over.

devx-admin

Share the Post: