ACC2000: How to Disable CTRL+ENTER in a Text Box or Memo Control (210207)



The information in this article applies to:

  • Microsoft Access 2000

This article was previously published under Q210207
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 Microsoft Access 2000, a user can insert a carriage return/line feed into a bound text box by pressing CTRL+ENTER. This key combination is a Windows shortcut recognized by all Microsoft Office products, including Access. However, in certain situations, you may want to prevent the user from inserting a carriage return/line feed into a given text box. This article demonstrates a user-defined Sub procedure that you can use to intercept these keystrokes within a given text box.

MORE INFORMATION

When a user presses CTRL+ENTER from within a bound text box on a form, a Windows shortcut results. The result is sent directly to the operating system and cannot be suppressed by Microsoft Access or any other program running under Windows.

To intercept the carriage return/line feed effect of these keystrokes, insert the following event procedure in the KeyDown event of the text box:

Sub Text1_KeyDown (keycode As Integer, shift As Integer)
   Dim shiftdown As Variant
   shiftdown = (Shift And CTRL_MASK)
   If shiftdown And (KeyCode = 13) Then SendKeys "{BS}"
End Sub
				

REFERENCES

For additional information about disabling keystrokes, click the article number below to view the article in the Microsoft Knowledge Base:

208826 ACC2000: How to Disable PAGE UP and PAGE DOWN Keys in a Form


Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto kbinfo KB210207