Selects the contents of a text box if the left mouse button is not down.
Intended to be called from the GetFocus event.
- Syntax
-
SelectActiveText
Call SelectActiveText
Remarks
This instruction will not select the contents
if the user clicks on the text box.
It can also be used on ComboBoxes with a Style of zero - Dropdown Combo.
Example
Sub Text1_GetFocus ()
Call SelectActiveText
End Sub
Source
Sub SelectActiveText()
Dim ctrl As Control
Const KEY_LBUTTON = &H1
On Error GoTo SelectActiveTextTrap
Set ctrl = Screen.ActiveControl
If IsLButtonDown() Then
ctrl.SelLength = 0
Else
ctrl.SelStart = 0
ctrl.SelLength = Len(ctrl.Text)
End If
SelectActiveTextTrap:
Exit Sub
End Sub
|