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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot focus a field or set 'SelStart'

Status
Not open for further replies.

1DMF

Programmer
Jan 18, 2005
8,795
GB
Hi,

I seem to be banging my head on a wall that is focusing a field and placing the carret at the end of the line.

I have the following code in a click event
Code:
=inputZoom("Notes")

The function is this..
Code:
Public Function inputZoom(sTitle As String, Optional ByRef CTRL As Variant)
 
 On Error Resume Next
  Dim ctl As Access.Control
  
    If Not IsMissing(CTRL) Then
        Set ctl = CTRL
    Else
        Set ctl = Screen.ActiveControl
    End If
    
    If ctl.Parent.Recordset.Updatable Then
        DoCmd.RunCommand acCmdSaveRecord
    End If
  
  DoCmd.OpenForm "inputPopUp", acNormal, , , , , sTitle
  Forms("inputPopUp").BindControl ctl
  
End Function

the BindControl sub does this
Code:
Public Sub BindControl(BoundControl As Access.TextBox)
  
  On Error GoTo errlbl
  
       
  Dim zoomCtl As Access.TextBox
  Dim ctl As Object
  
  Set zoomCtl = Me.inputTextBox
  Set ctl = BoundControl.Parent
  
  Do While Not TypeOf ctl Is Access.Form
    Set ctl = ctl.Parent
  Loop
  
  Set oControl = BoundControl
  
  Set Me.Recordset = ctl.Recordset
  
  With zoomCtl
    .ControlSource = BoundControl.ControlSource
    .Locked = BoundControl.Locked
    .ValidationRule = BoundControl.ValidationRule
    .ValidationText = BoundControl.ValidationText
    .Format = BoundControl.Format
    .ControlTipText = BoundControl.ControlTipText
    .ForeColor = BoundControl.ForeColor
  End With
  
[b]
    Me.inputTextBox.SetFocus
    If Not IsNull(Me.inputTextBox) Then
        Me.inputTextBox.SelStart = Len(Me.inputTextBox)
    Else
        Me.inputTextBox.SelStart = 0
    End If
[/b]    

  Exit Sub
  
errlbl:
  MsgBox err.Number & " " & err.Description
  Exit Sub
End Sub

as you can see by the highlighted code it should focus the field and set the carret position , only it doesn't?

Why?

If I placed right at the end of the inputZoom function
Code:
msgbox Screen.ActiveControl.Name

I get
inputTextBox
so the correct field is active, and what's even more bizzare to me is when I click 'OK' the field then has the correct focus and the carret is at the end of the line.

Take away that debug statement, it doesn't work, keep the debug statement, it works?

I'm baffled as to why it is behaving like this, can any one help explain why and how I fix it?

Thanks,
1DMF.

"In complete darkness we are all the same, it is only our knowledge and wisdom that separates us, don't let your eyes deceive you."

"If a shortcut was meant to be easy, it wouldn't be a shortcut, it would be the way!"

Free Electronic Dance Music Download
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top