Hello,
I have a userform for text input - 3 text boxes. Each must meet a certain criteria to be passed as ok. All this is done and working.
What I am struggling with though is set focus. What I want, is if the first text box is passed OK but the other 2 aren't, the first text box with the error should be given focus. If text box 2 is ok but 1 and 3 are wrong, 1 should be given focus. If 1 and 2 are ok and 3 is wrong, 3 should have focus. And so on.
I am doing this in a controls loop, then passing the text box object to a procedure which does the error checking and set the captions of appropriate labels and changes the border colour of the text box.
As the SetFocus is currently part of the loop, it always sets focus to the last box with the error, because it just carries on the loop.
I can't quite work out how to stop it continuing to set focus once focus has already been set. I don't want to exit the loop once an error is encountered because I want all error fields to show on in one go when pressing OK.
Any ideas? In VBA can you find the first control that matches type and has certain criteria (i.e. specific border colour)? Without another loop?
If you can, I could do all the error checking and flagging first, then something like this:
Control.Parent.Controls(first textbox with red border).SetFocus
Thanks
Bookmarks