ACC97: Using Tab Key to Insert Tab Character in RichText Control

Last reviewed: June 16, 1997
Article ID: Q170141
The information in this article applies to:
  • Microsoft Access 97

SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

In a RichTextBox control, the default behavior of the TAB key is to move the focus to the next control in the tab order of a form. This article shows you how you can use the TAB key to insert a tab character into a RichTextBox control.

The sample function ctlRichText1_KeyDown() traps for the TAB key in the KeyDown event of the RichTextBox control. It prevents the control from losing focus, and then uses the SelText property of the control to insert the tab.

MORE INFORMATION

  1. Create a new form not based on any table or query in Design view.

  2. On the Insert menu, click ActiveX Control.

  3. In the Insert ActiveX Control dialog box, select Microsoft RichText Control, and then click OK.

  4. Set the control's Name property to ctlRichText1.

  5. Add two text boxes to the form.

  6. On the View menu, click Code. Type the following procedure:

          Private Sub ctlRichText1_KeyDown(KeyCode As Integer, _
    
                ByVal Shift As Integer)
             Dim rtf As RichTextBox
             Set rtf = Me!ctlRichText1.Object
             If KeyCode = 9 Then  ' TAB key was pressed.
                ' Ignore the TAB key, so focus doesn't
                ' leave the control
                KeyCode = 0
                ' Replace selected text with the tab character
                rtf.SelText = vbTab
             End If
          End Sub
    
    

  7. Switch the form to Form view. Note that pressing the TAB key now inserts a tab character in the RichTextBox Control. To exit the RichTextBox control, use your mouse pointer. Note also that the TAB key behaves as it normally does when one of the text boxes has the focus.

REFERENCES

For more information about the methods and properties of the RichTextBox control, open a module in a database containing a form with a RichTextBox control and press F2. In the Object Browser, select RichTextLib from the list of Libraries, and then select RichTextBox from the list of Classes.


Keywords : IntpCstm kbcode kbinterop
Version : 97
Platform : WINDOWS
Hardware : x86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 16, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.