Data Entry

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Mallard
    New Member
    • Jul 2008
    • 1

    #1

    Data Entry

    Objective : The user requires to enter data into a text field without having to highlight it before typing over what was there before. This works if the user uses the up/down key to go to the next record, but when they use the mouse to go to a specific row I'm trying to find a way of highlighting that field (ie in reverse video). I've tried using the code: SendKeys "+^{RIGHT}" in the 'OnFocus' event but to no avail.
  • hjozinovic
    New Member
    • Oct 2007
    • 167

    #2
    Hey Mallard!

    You can use this code in the control's OnClick event:
    Code:
    Private Sub txtSearchString_Click()
    Me.txtSearchString.SelStart = 0
    Me.txtSearchString.SelLength = Len(Nz(Me.txtSearchString, 0))
    This way when you click on that control (txtSearchStrin g in my example)
    the content of the control is selected and you can type over it.
    Note that Nz(ControlName, 0) is used in order to avoid err when control is empty (null).
    Hope it helps, H.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32669

      #3
      That should work - except possibly change the third line so that Nz() uses "" if value Null instead of 0.
      Code:
      Private Sub txtSearchString_Click()
      Me.txtSearchString.SelStart = 0
      Me.txtSearchString.SelLength = Len(Nz(Me.txtSearchString, ""))
      ...
      Or why not use the With construct to make the code more efficient and easier to read :
      Code:
      Private Sub txtSearchString_Click()
      With Me.txtSearchString
        .SelStart = 0
        .SelLength = Len(Nz(.Value, ""))
      End With
      ...

      Comment

      Working...