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
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.
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.
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.
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.
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.
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.