+ Reply to Thread
Results 1 to 4 of 4

Textbox dilemma

  1. #1
    Registered User
    Join Date
    03-21-2005
    Posts
    1

    Textbox dilemma

    Ok Guys - for those smart enough to help me with this you will find what I am trying to achieve in the following code self evident

    - for some reason the SetFocus command will not work when I try to return it to TextBox8 on exit event - it simply ignores that line of code - but it will set the focus on other textboxes. I know the answer will be simple but I have literally spent about 10 hours on this ridiculously small issue.

    Code:

    Private Sub TextBox8_Exit(ByVal Cancel As MSForms.ReturnBoolean)

    Dim howmany

    howmany = TextBox8.TextLength

    If TextBox8.TextLength = "17" Then
    Me.TextBox7.SetFocus

    Else

    MsgBox ("Must be 17 Characters you have entered " & howmany & " Characters")
    Me.TextBox8.SetFocus

    End If
    End Sub

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258
    Hello Stewm,

    The event is probably not firing. Enter and Exit events are tricky to work with. You would be better off to place your code in the AfterUpdate event. To better understand the Enter and Exit events, see the Remarks section I have included.

    Remarks:

    The Enter and Exit events are similar to the GotFocus and LostFocus events in Visual Basic. Unlike GotFocus and LostFocus, the Enter and Exit events don't occur when a form receives or loses the focus.
    For example, suppose you select the check box that initiates the Enter event. If you then select another control in the same form, the Exit event is initiated for the check box (because focus is moving to a different object in the same form) and then the Enter event occurs for the second control on the form.

    Because the Enter event occurs before the focus moves to a particular control, you can use an Enter event procedure to display instructions; for example, you could use a macro or event procedure to display a small form or message box identifying the type of data the control typically contains.

    Copyright(c) 1996 Microsoft Corporation.

    _________________________________________________________________

    Sincerely,
    Leith Ross

  3. #3
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Stewm

    Can't you just set cancel to true?
    Please Login or Register  to view this content.

  4. #4
    Valued Forum Contributor tony h's Avatar
    Join Date
    03-14-2005
    Location
    England: London and Lincolnshire
    Posts
    1,187
    When trying to debug event problems of this sort you cannot step through the code as that process affects the events. There are a couple of options for finding out what is happening (the first stage in finding out how to put it right) all involve keeping a trace of the code execution. The simplest trace is to write to the immediate pane: insert a line of code before the "if" statement such as

    debug.print now, textbox8.textlength,textbox8.text

    then when you have run the code you will see the text appear in the immediate pane and the values. This might give you a clue. If the text does not appear the event has not triggered.

    hope this helps

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1