vbTAB disabling 
Author Message
 vbTAB disabling

Hi,

in my form, I want to disable the TAB key.
I have tried to do this using the ascii code for vbTAB (9), but it
does'nt recognize this at all.

At the same time, I am simulating the TAB key Using the ENTER key by
doing:
if keyascii=13 then sendkeys vbtab.
This is working fine, but it does produce an audible signal (beep)
How can I turn this off?

thx,

James



Mon, 10 May 2004 23:32:23 GMT  
 vbTAB disabling
This sort of stuff is a nightmare.

One would have thought that setting a Form's KeyPreview to True would
do just that - but it does not - some controls steal certain keys
regardless.

You also have a circular problem - if you want to disable the Tab key
then you will still have it disabled when you send in A TAB KEY using
SendKeys.

Here is a sample of 'burning off keys' to prevent beeps
(more after sample)

Option Explicit

' Start with two Textboxes
' Add other controls to test

Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    Select Case KeyCode
           Case vbKeyTab: Me.Print "Form Tab": KeyCode = 0
           Case vbKeyReturn: Me.Print "Form Return": KeyCode = 0
           Case vbKeyUp: Me.Print "Form Up": KeyCode = 0
           Case Else: Me.Print KeyCode
    End Select
End Sub

Private Sub Form_KeyPress(KeyAscii As Integer)
    Select Case KeyAscii
           Case vbKeyTab: Me.Print "Form Tab": KeyAscii = 0
           Case vbKeyReturn: Me.Print "Form Return": KeyAscii = 0
           Case vbKeyUp: Me.Print "Form Up"
           Case Else: Me.Print KeyAscii
    End Select
End Sub

Private Sub Form_Load()
    Dim C As Control
    Me.KeyPreview = True
    For Each C In Controls
        C.TabStop = False
    Next
End Sub

=========

You will find that Textboxes are just about manageable - but
Commandbuttons a nightmare.

In fact this key stealing stuff is by design - Windows sends a message
to the control with focus ( WM_GetDlgCode ) and if it replies with :-
  DLGC_WANTARROWS or DLGC_WANTTAB or DLGC_WANTALLKEYS

Then the control gets all keys.

However this involves a lot of sub classing and is a pain to implement
in VB

Quote:

>Hi,

>in my form, I want to disable the TAB key.
>I have tried to do this using the ascii code for vbTAB (9), but it
>does'nt recognize this at all.

>At the same time, I am simulating the TAB key Using the ENTER key by
>doing:
>if keyascii=13 then sendkeys vbtab.
>This is working fine, but it does produce an audible signal (beep)
>How can I turn this off?

>thx,

>James



Tue, 11 May 2004 03:14:19 GMT  
 vbTAB disabling
Another poster described the circular problem of turning off TAB
processing while also trying to turn CRs into TABs, but I didn't see
where he answered your second question.  To get rid of the beep:

if keyascii=0 then
   sendkeys vbtab
   keyascii=0
end if

chris judge

Quote:

> Hi,

> in my form, I want to disable the TAB key.
> I have tried to do this using the ascii code for vbTAB (9), but it
> does'nt recognize this at all.

> At the same time, I am simulating the TAB key Using the ENTER key by
> doing:
> if keyascii=13 then sendkeys vbtab.
> This is working fine, but it does produce an audible signal (beep)
> How can I turn this off?

> thx,

> James



Tue, 11 May 2004 14:34:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. If statement for vbTab's presence

2. vbTab export

3. Please help with vbTab Export

4. vbTab not working in Excel

5. vbTab justification options?

6. vbTab

7. Size setting for vbTab

8. Javascript and vbTab and SQLserver

9. Combobox with vbTab

10. RichTextBox: Getting and setting Tab size (vbTab)

11. MSHFlexGrid -- vbTab

12. TreeView: Aligning data problem (vbTab doesn't work)

 

 
Powered by phpBB® Forum Software