By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,652 Members | 1,905 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,652 IT Pros & Developers. It's quick & easy.

Data Entry

P: 1
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.
Aug 8 '08 #1
Share this Question
Share on Google+
2 Replies


100+
P: 167
Hey Mallard!

You can use this code in the control's OnClick event:
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSearchString_Click()
  2. Me.txtSearchString.SelStart = 0
  3. Me.txtSearchString.SelLength = Len(Nz(Me.txtSearchString, 0))
This way when you click on that control (txtSearchString 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.
Aug 8 '08 #2

NeoPa
Expert Mod 15k+
P: 31,487
That should work - except possibly change the third line so that Nz() uses "" if value Null instead of 0.
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSearchString_Click()
  2. Me.txtSearchString.SelStart = 0
  3. Me.txtSearchString.SelLength = Len(Nz(Me.txtSearchString, ""))
  4. ...
Or why not use the With construct to make the code more efficient and easier to read :
Expand|Select|Wrap|Line Numbers
  1. Private Sub txtSearchString_Click()
  2. With Me.txtSearchString
  3.   .SelStart = 0
  4.   .SelLength = Len(Nz(.Value, ""))
  5. End With
  6. ...
Aug 9 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.