Microsoft KB Archive/210611

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

Article ID: 210611

Article Last Modified on 6/24/2004

-

APPLIES TO


 * Microsoft Access 2000 Standard Edition

-



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).



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.



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

<div class="references_section">