VBA-excel,text box-enter event

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ronakinuk
    New Member
    • Jan 2009
    • 15

    VBA-excel,text box-enter event

    hello i need help in this please. i dont have much knowledge of VBA but can do very basic things by learning from different forums.

    i want to create one excel application where there will be few userforms. and on each there will be some text boxes.

    i want it to work like this.
    if user puts number 2 in textbox1 on userform1 and then PRESS ENTER, unload userform1 and show userform2, but if user puts 3 in textbox1 on userform1 and PRESS ENTER then unload userform1 and show userform3 and so on.......... pressing enter is very important event.

    i have tried it with click event and it is working but it needs to be enter event.

    thanks a lot.
    ronak
  • MikeTheBike
    Recognized Expert Contributor
    • Jun 2007
    • 640

    #2
    Hi

    Have you tried the 'TextBox1_After Update' Event !?

    MTB

    Comment

    • ronakinuk
      New Member
      • Jan 2009
      • 15

      #3
      thanks for your reply

      have tried the afterupdate event in the textbox, but that event is fired only if the form is closed by the user, it doesnt work with pressing enter key.

      the code i tried was
      Private Sub TextBox1_AfterU pdate()
      If TextBox1.Text = "2" Then UserForm2.Show
      If TextBox1.Text = "3" Then UserForm3.Show
      End Sub

      may be i dont know how to write the code, can you please help me with the code so that after putting 2 and pressing the enter key the userform1 will close and userform2 will show........... .and so on with 3, 4, 5.........till 10.

      i have previously tried with userform1_click event like below.but it doesnt unload userform1 at the same time.

      Private Sub UserForm_Click( )
      If TextBox1.Text = "2" Then UserForm2.Show
      If TextBox1.Text = "3" Then UserForm3.Show
      End Sub

      thanks

      Comment

      • MikeTheBike
        Recognized Expert Contributor
        • Jun 2007
        • 640

        #4
        Hi again

        I do not know why your code does not work but this
        Code:
        Private Sub TextBox1_AfterUpdate()
            If TextBox1.Text = "2" Then UserForm2.Show
            If TextBox1.Text = "3" Then UserForm3.Show
        End Sub
        works OK on my PC (running Excel 2k3).

        Perhaps some else can shed some light on this. I don't know if there are any setting in Excel/VBA to disable control event.

        Do any of the forms or contols events work ??


        MTB

        Comment

        • samyp

          #5
          Thanks a bunch MikeTheBike that solved a problem I had as well

          Comment

          Working...