Setfocus issue

  • Gents


    I'm using the following to check for a valid entry in combobox1 and throw out an error message if not true.


    Can anyone spot why my focus is not returning to the combobox on acknowledging the message box. The cursor simply sits on whatever control I selected to exit the combobox



    Any suggestions appreciated

  • Re: Setfocus issue


    My understanding is that the _Exit event is called just before the control loses focus. So using .SetFocus on it just before it loses focus anyway (transfered to the control that caused the exit) serves no purpose.

    I think if you add

    Code
    Cancel = True



    Then that will cancel the _Exit event and then the focus should be on your ComboBox1

  • Re: Setfocus issue


    Rob


    Carrying on from my initial post i had to further adapt the code in an attempt to empty the userform of data. This was done using the following



    If I have a form only using textboxes everything works fine but when I apply the above to a form containing textboxes and comboboxes I run into the original problem of the focus falling on whichever control was clicked on to exit combobox2.


    Any further insight would be helpful.


    Regards


    Simpo

  • Re: Setfocus issue


    I am slightly shooting in the dark here as I am guessing about the rest of your Form code, but try this:



    If that achieves what you want then I think the issue was that in your original sub you were exiting from the ComboBox2_Exit event when its value was vbNullString without setting Cancel. So when you emptied your userform you were setting ComboBox2 to vbNullString, that prompted the exit without Cancel.

  • Re: Setfocus issue


    Rob


    I can see that this makes perfect sense, however on putting the code in and testing it I'm getting a "method or datamember not found" error relating to the "or ctrl is msforms.combobox" line


    The form definitely contains both types of controls, can you spot something obvious in the code as it seems ok to me

  • Re: Setfocus issue


    Give this a try


    Code
    If TypeOf ctrl Is MSForms.TextBox Or ctrl Is MSForms.ComboBox Then ctrl.value = vbNullString

    [SIZE=3]The Only Dumb Question Is A Question Not Asked.[/SIZE]

  • Re: Setfocus issue


    No joy I'm afraid, throws up a seperate set of issues. I need to rethink this and start a new thread when I hit the wall.


    Thanks for your help it's given me some direction to think about


    Simpo

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!