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

Detecting Tab key on TextBox control

Status
Not open for further replies.

ricaforrica

Programmer
Jun 30, 2005
65
PT
Hello!

I'm creating a Word template. I have 3 textboxes

-> one for username (enabled)
-> one for a description (disabled)
-> one for password (enabled)


Then I have a button wich, when pressed, runs a Macro that checks an Oracle database to validate username/password. This is working!

What I need is to implement an event that detects the TAB key on the username textbox, goes to the database fetch the description and stores it in the description textbox, and finally set the focus to the username textbox...

I'm trying to use _KeyUp event and test if the key is TAB with:

if KeyCode = Chr(vbKeyTab) then...

but it isn't working!

Can anyone help me on this?
Thanks a lot!

Ricardo Pinto
 
MSForms.ReturnInteger returns Long, so:

if KeyCode = vbKeyTab then...

combo
 
Hello again!

I figured out what was the mistake:

if KeyCode = Chr(vbKeyTab) then

No need for Chr(..)! The following is enough:

if KeyCode = vbKeyTab then

Now I have only one problem: how should I set the focus on the password textBox?

Thank you once again!

Ricardo Pinto
 
Thanks Combo!

You're quicker than I ;)
Any idea on the focus issue?
 
Well, still searching!

I found this:

TextBox3.Activate

and it works. But it kind of refreshes the textboxes: the labels disappear for a second and back again :S

Strange behaviour! Any other solution?
Thanks in advance,

Ricardo
 
Hi,
you can use SetFocus method, common for 'Controls' collection

combo
 
Hello,

I don't seem to have the Controls collection available... Am I supposed to add any reference?

By the way, using TextBox.Select works as well, but with the same blinking effect!

Ricardo
 
Hi,

I wasn't using labels as I said before, but pure word text.
Unfortunately, even with a label control the blinking effect still ocurred...

What might be doing this?

Ricardo
 
Another correction!

The labels work, but I have another text in the document which blinks :S

Can you help find another solution?
Thank you!

Ricardo
 
I'm going to shutdown this thread and open a new one with the appropriate title...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top