none
Unable to set focus on a set box RRS feed

  • Question

  • I am using the code below to set focus on a text box if the use did not enter a  value and click the next button. But it doesn't work. Program continues to next statement.Thanks for your time

            If txtSchName.Text = "" Then
                MsgBox("Enter School Name to continue")
                Me.txtSchName.Select()
            End If

    Friday, January 12, 2018 5:56 PM

Answers

  • Try

    Me.ActiveControl = Me.txtSchName

    Then you need to use e.g.

    Exit Sub for a procedure or event or Exit Function for a function etc.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Friday, January 12, 2018 5:59 PM
    Moderator
  • Maybe add Return before End If?

    • Marked as answer by alobi Friday, January 12, 2018 8:54 PM
    Friday, January 12, 2018 7:45 PM

All replies

  • Try

    Me.ActiveControl = Me.txtSchName

    Then you need to use e.g.

    Exit Sub for a procedure or event or Exit Function for a function etc.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites


    Friday, January 12, 2018 5:59 PM
    Moderator
  • Hi

    Do you get the message box?

    Is the TextBox truly empty - no space characters?

    When you say continues to next statement, do you mean the one AFTER the End If ?Have you tried setting a breakpoint on the If .... Then line and examine the Text part of txtSchName.Text?

    Have you made sure that the code block you show is actually being reached?



    Regards Les, Livingston, Scotland

    Friday, January 12, 2018 6:03 PM
  • Maybe add Return before End If?

    • Marked as answer by alobi Friday, January 12, 2018 8:54 PM
    Friday, January 12, 2018 7:45 PM