ACC1x: Sample Function to Make ENTER Add Lines in a Text Box

Last reviewed: April 2, 1997
Article ID: Q89590
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1

SUMMARY

Text boxes in Microsoft Access do not support using the ENTER key to add lines within a field. When ENTER is pressed in a text box, the next field or control is selected. This article describes a sample function that you can use to modify the action that results when you press ENTER so that a line is added to the current field instead of selecting the next field.

NOTE: Microsoft Access 2.0 introduces the new EnterKeyBehavior property which can be set to "New Line in Field."

MORE INFORMATION

The following sample function changes the behavior of the ENTER key in text boxes to allow adding lines instead of selecting a different field or control. This code should be attached to the BeforeUpdate event of the text box:

In the Declarations section of a module, enter the following:

   Option Explicit
   Declare Function GetKeyState% Lib "user.exe" (ByVal nKey%)
   Const VK_RETURN = &HD

The following is the sample function MakeEnterWork():

   Function MakeEnterWork()
      If GetKeyState(VK_RETURN) < 0 Then
         DoCmd CancelEvent
         SendKeys "^{ENTER}"
      End If
   End Function

NOTE: Some change must be made to the text box before this function will work because Microsoft Access evaluates controls only after they have been modified.


Additional query words: carriage return memo textbox
Keywords : GnlGlobl kbusage
Version : 1.0 1.1
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: April 2, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.