Results 1 to 2 of 2
  1. #1

    EnterKeyBehaviorProperty (VBA for MS Word 97)

    I have created a template form which contain an AutoNew macro which brings up a series of prompted text boxes. I am attempting to modify the EnterKeyBehaviorProperty so that upon depression of the Enter Key, the current text box window closes and the next one opens. In other words, altering the Enter Key function to have the same effect as clicking on the OK button within the pop-up window. I have attempted inserting in different line locations variations on a theme of "Textbox1.EnterKeyBehavior = False" to make the desired Enter Key behavior change. I have not met with success. There are 12 pop-up windows in sequence which I need the EnterKeyBehavior to function to close the window and move on to the next. After the sequence of text box windows, a prompt appears directing the user as to what to do to complete the template form. The code without the EnterKeyBehavior modification is as follows:

    Sub AutoNew()
    ' AutoNew Macro
    ' Macro recorded 08/22/01 by Thomas Courtney

    'MsgBox "Edit each of the greyed-out pull down, check box, and fill-in fields.", vbExclamation, "To Complete the Solid Waste Disposal Form:"
    End Sub

    What is the proper syntax for changing the EnterKeyBehavior and where do I insert it? If it appears that this inquiry came from a neophyte, your assessment is correct.

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Silicon Valley, USA
    Thanked 94 Times in 90 Posts

    Re: EnterKeyBehaviorProperty (VBA for MS Word 97)

    Here's another option. When the user presses Enter, focus will move to the button or whatever the next control is in the UserForm. In order for this to work, there must be a second control.

    In your main module:

    strVariable1 = UserForm1.TextBox1.Value
    Unload UserForm1
    strVariable2 = UserForm2.TextBox1.Value
    Unload UserForm2

    In your userforms:

    <pre>Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    'this event procedure is triggered when the user presses Enter in the textbox
    If Me.TextBox1.Value = vbNullString Then
    Cancel = True 'don't go anywhere, the textbox is empty
    Cancel = False 'we are out of here
    Me.Hide 'close the userform, return to main module
    End If
    End Sub</pre>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts