Results 1 to 10 of 10

Thread: Excel Textbox Exit no longer works

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    Excel Textbox Exit no longer works

    Hello,

    I am fairly new to VBA programming. Actually I have been programming in BASIC virtually since it was invented, however all the Object stuff is new to me. I have created a form with several frames. I need the frames to allow selection choices for each category of items I have to select from. Anyway, when a user would hit tab or enter, the exit routine would fire and all was good. Now, however, the exit routine no longer fires. In fact, I can see that the focus jumps to my cancel button, which is on the form, but not within a frame.

    I have searched the forum for "textbox" and "focus" issues, but none of them seem to apply directly to the behaviour I am seeing. So I have two questions:

    1. Can anybody explain to me how the focus on a form works? Especially in light of a form with multiple frames buttons and textboxes?

    2. Any ideas how I have destroyed the orginal behaviour and how I might correct it?
    Last edited by Budman50; Mar 3rd, 2006 at 04:46 PM. Reason: Correct typos

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel Textbox Exit no longer works

    Welcome to the Forums.

    1. check the event for the textbox is the LostFocus event? Place a breakpoint on your event to make sure its fire'ing and press F8 to step through it to see how its executing. Make sure its not erroring out of the event bypassing your code.

    2. Depends on #1.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    Re: Excel Textbox Exit no longer works

    This is VBA for Excel (2002) and no LostFocus event shows up in the Textbox code window. I did try BeforeUpdate and AfterUpdate and neither of these fire as well. One of the things I read to try was to set the focus back at the Frame_Exit point. I tried it and the frame exit does not fire as well.

    I can initially get the focus into the Textbox and even edit the text, it's when I hit return or tab that nothing seems to happen, except the caret (cursor) disappears from the Textbox and the Cancel button gets a box about it, indicating it has the focus. I can click back on the textbox and regain the focus. Once, I got the error 2110, something about unable to place focus... but I can't seem to find more details on that error.

    What kills me, is this used to work, before I had so many controls and frames on the UserForm.... so I know it is something specific I did to suppress it's action.

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel Textbox Exit no longer works

    Are you coding behind the sheet that contains the controls or do you have the controls in a userform?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    Re: Excel Textbox Exit no longer works

    I have it in a Userform1 and I have seven frames, additionally, some of the controls are outside the frames.

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel Textbox Exit no longer works

    Even with textboxes in frames the _Exit event still fires for me. Maybe you can post your code?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    Re: Excel Textbox Exit no longer works

    Ok, here is the source files for the application I am writing. Be warned, if you are a seasoned VB programmer, you will find TONS of stuff that could be done better. I am not opposed to learning better ways, I am just new to this and I don't want you to be too disappointed.

    This form was created to help a bunch of Component Engineers with the RoHS conversion (lead free). There are 20K part to convert and I have been authorized to help speed up the process any way I can. Hence, I started to attempt to cast the rules of selection within this form.

    I have included a test file, one line each of the two types we are dealing with. Try and edit the Manufactures Name textbox, and you will see what I mean. BTW, the program will not open unless you select an entire row from the test spreadsheet.

    Thanks,

    Buddy
    Attached Files Attached Files

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Excel Textbox Exit no longer works

    TextBox2 gets disabled because of the sub - Sub NewPartNumber(newstring As String). In it - UserForm1.TextBox2.Enabled = False is being set to disabled. This is why it wont allow you to click into it if you once passed an invalid newstring.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    Re: Excel Textbox Exit no longer works

    Thank you, but that's not possible. NewPartNumber is not being executed, as it is in the Exit routine that is not being called. Hence, it is never getting executed. I can prove it by setting a breakpoint and it never gets hit, even during the startup.

    Taking your cue, however, I did search for all the instances of TextBox2 to see if it was disabled during the peroid of time I needed to exit the box and it is not. I even commented out several places where I was sure was not affecting it, just in case. The behaviour still acts the same, no exit routine is fired... focus still goes to the Cancel button.

  10. #10

    Thread Starter
    New Member
    Join Date
    Mar 2006
    Posts
    7

    Re: Excel Textbox Exit no longer works

    Using the VBA help system, I found an Enter and Exit description that says it is like got_focus and lost_focus functions. I tried their example program, only to find it does not work. I then tried to add the enter event and it did not solve the problem either, exit event still does not execute.

    Anyway, rather than track what happened to the focus, I needed to know when the box was being exited. I found an event associated with a textbox called keydown. I found that this echos the key in the KeyCode argument. So, I trap on a Tab (9) OR an Enter key (13) and do the things I need to be done. So, although it may not be correct, at least it is working.

    Thanks for your help!!

Posting Permissions

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



Click Here to Expand Forum to Full Width