AutoSelect Text Box Contents

Users often find it faster to retype the entire contents of a text box rather than position the cursor within the data, and then edit the data. This is especially true if the length of the data is short or if the data isn’t visible, as with a password field, for example. Double-clicking or using a mouse to select the control’s contents is slow and inconvenient.I created this small routine to automatically select all data within a control. I place this routine in a code module so that it’s accessible from all forms. I call this routine from a control’s GotFocus event. This way, the data is selected if the user tabs to or clicks on the control, or if a data validation routine does a SetFocus:

 Private Sub MyTextBox_GotFocus()	AutoSelect MyTextBoxEnd SubThe AutoSelect routine is quite simple:Sub AutoSelect(SelObject As Control)' The AutoSelect routine "selects" the ' control's entire contents as if it were' doubled-clicked.	SelObject.SelStart = 0	If TypeOf SelObject Is MaskEdBox Then		SelObject.SelLength = Len(SelObject.FormattedText)	Else		If TypeOf SelObject Is TextBox Then			SelObject.SelLength = Len(SelObject.Text)		End If	End IfEnd Sub
Share the Post:
Share on facebook
Share on twitter
Share on linkedin


The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS