Max Wanadoo
max.wanadoo at gmail.com
Fri Apr 3 04:37:39 CDT 2009
Rocky,
Dont know if you solved this last night but if not the code below will
select the entire field whether tabbed in or clicked in, regardless of hte
global setting in Tools/Options.
Max
ps. Haven't got access to previous correspondece/postings so the title may
be out of sync. Sorry.
' Test the ability to select the entire contents of a bound field regardless
of the setting in Tools/Options/Keyboard
' tests only a Currencyfield,Datefield,Numberfield,Stringfield
' does not work for boolean fields
' for each field we need to call the sub for both the OnClick event AND the
GotFocus event
' Max Sherman Apr 2009
Option Compare Database
Option Explicit
Private ActiveCtl As Control
Private Sub BooleanField_Click()
' do not call sSelLength for boolean
End Sub
Private Sub BooleanField_GotFocus()
' do not call sSelLength for boolean
End Sub
Private Sub CurrencyField_Click()
Call sSelLength
End Sub
Private Sub CurrencyField_GotFocus()
Call sSelLength
End Sub
Private Sub DateField_Click()
Call sSelLength
End Sub
Private Sub DateField_GotFocus()
Call sSelLength
End Sub
Private Sub NumberField_Click()
Call sSelLength
End Sub
Private Sub NumberField_GotFocus()
Call sSelLength
End Sub
Private Sub StringField_Click()
Call sSelLength
End Sub
Private Sub StringField_GotFocus()
Call sSelLength
End Sub
Private Sub sSelLength()
On Error GoTo errhandler
Set ActiveCtl = Application.Screen.ActiveControl
Debug.Print Application.Screen.ActiveControl.Name
With ActiveCtl
.SetFocus
.SelStart = 0
.SelLength = Len(Nz(ActiveCtl, "")) + 1
End With
exithere:
Exit Sub
errhandler:
Select Case Err.Number
Case 2474 ' not active control
Debug.Print Application.Screen.ActiveControl.Name
MsgBox Application.Screen.ActiveControl.Name
Case Else
MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
End Select
Resume exithere
End Sub