Setfocus on textbox

J

Jason

Dear all,

I want to set the focus in the one textbox even if I press <enter> or <tab>
key until I use the mouse to point to another textbox. How can I do ?


Thank you

Jason.
 
D

Douglas J. Steele

Why would you hit the Tab key? Tabs don't work in Access controls...

To stay in the same textbox when hitting Enter, set the EnterKeyBehavior
property for the text box.
 
R

Rob Parker

Hi Doug,

Why wouldn't you hit the Tab key? Unless you've set tab stop to No for
every control on your form, the Tab key will cycle through the controls
(move focus to the next control in the tab order); it may even move to the
next record, depending on the Cycle property setting for the form itself.

I think the OP needs to put code into the KeyDown event for the control in
question, and do nothing if the key code is either 9 (tab key) or 13 (enter
key). It's not something I've ever done, so I don't know exactly what is
needed to cancel the key's action (the KeyDown event doesn't have a Cancel
parameter), but it shouldn't be too hard.

Rob
 
D

Douglas J. Steele

You're right. I was reading it as he wanted to be able to insert tabs into
the text.

Jason: Set the KeyPreview property of the form to True, and add code like
the following to the KeyPress event of your textbox:

Private Sub Text0_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case 9, 13
KeyCode = 0
Case Else
End Select
End Sub

(replace Text0 with the actual name of your text box)

Note that the above means that the Enter key will be ignored. If you want
the Enter key to put a carriage return/line feed into your text, remove the
", 13" from the code above, and set the EnterKeyBehavior property as I
previously suggested.

Sorry for the confusion.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top