Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Insert the Tab Character in a RichText Control


View products that this article applies to.

This article was previously published under Q210611
Moderate: Requires basic macro, coding, and interoperability skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

↑ Back to the top


Summary

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.

↑ Back to the top


More information

  1. Start Microsoft Access and open any database.
  2. In Design view, create a new form not based on any table or query.
  3. On the Insert menu, click ActiveX Control.
  4. In the Insert ActiveX Control dialog box, click Microsoft RichText Control, and then click OK.
  5. Set the control's Name property to ctlRichText1.
  6. Add two text boxes to the form.
  7. 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
    					
  8. Switch 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.

↑ Back to the top


References

For more information about ActiveX controls, click Microsoft Access Help on the Help menu, type activex in the Office Assistant or the Answer Wizard, and then click Search to view the topics returned.

For more information about the methods and properties of the RichTextBox control, open a database containing a form with a RichTextBox control. On the View menu, click Object Browser. In the Object Browser, select RichTextLib in the list of Libraries, and then select RichTextBox in the list of Classes.

↑ Back to the top


Keywords: KB210611, kbinfo, kbhowto

↑ Back to the top

Article Info
Article ID : 210611
Revision : 2
Created on : 6/24/2004
Published on : 6/24/2004
Exists online : False
Views : 321