killing tab-key in a function

  • Thread starter Thread starter Jesper F
  • Start date Start date
J

Jesper F

I can prevent the tabkey from moving the focus to the next
control by placing this in the keydown-event of the
control:

If keycode = vbKeyTab Then
keycode = 0
End If

However - I can't seem to get it to work if I try to place
the code in a public function. I'd like to be able to just
write "=notab()" as the function name in the keydown-event
in the property sheet of the control and include the above
in the notab-function placed in a module.
Is this possible?
 
You might check out the "cycle" property of your forms.

Thanks, but it doesn't apply in this case. I just want to
halt the cursor in the all the controls where I
specify "=notab()" in the keydown event of the property
sheet.
 
The problem is your idea would work if the sub did not have two parameters.

So, for most events, you can specify a function name..but in your function
name, how does the KeyCode value get set? (it can't).

However, you could use the forms "global" keydown event, and then for each
control that you want to disable the tab key, you could put the following in
the controls "tag" property:


NoTab

Then, in the forms global keydown event, you use:



if screen.ActiveContorl.Tag = "NoTab" then
if KeyCode = vbKeyTab then
keyCode = 0
endif
endif

So, while you don't have a global code function, at least you only have the
above 5 lines of code for each form....
 
Albert D. Kallal said:
However, you could use the forms "global" keydown event, and then for
each control that you want to disable the tab key, you could put the
following in the controls "tag" property:
[...]

Nice answer, Albert!
 
-----Original Message-----
The problem is your idea would work if the sub did not have two parameters.

So, for most events, you can specify a function name..but in your function
name, how does the KeyCode value get set? (it can't).

However, you could use the forms "global" keydown event, and then for each
control that you want to disable the tab key, you could put the following in
the controls "tag" property:


NoTab

Then, in the forms global keydown event, you use:



if screen.ActiveContorl.Tag = "NoTab" then
if KeyCode = vbKeyTab then
keyCode = 0
endif
endif

Enlightning! Thanks for your help.
 
Back
Top