none
Excel VBA code/textbox enter event

    Question

  • Hello

    I am trying to make few userforms in EXCEL VBA.

    I have 10 userforms and on every forms there are few textboxes. I wonder if somebody help me with coding and explanation of the following.

     

    on starting the macro, userform1 should come up, and

     

    if user puts 2 in textbox1 on userform1,and press ENTER(while curser still in textbox1),then only, userform1 should unload and userform2 should show.

    if user puts 3 in textbox1 on userform1,and press ENTER(while curser still in textbox1),then only, userform1 should unload and userform3 should show.

    and so on...................

     and then on any form if user presses F2 key, the current form should unload and previous form should come up.

     

    thanks a lot for help.

     

     

    Tuesday, January 27, 2009 10:42 PM

Answers

  • Here is a possible hint.

    1. For your macro to show the form use

    UserForm1.Show

    2. To move to another form / previous form etc, use the Keydown event of particular textboxes. The following code will close the current form and open the UserForm2 if the user presses Enter key

     

    Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)  
        If KeyCode = 13 Then 
            If TextBox1.Text = 2 Then 
                Unload Me 
                UserForm2.Show  
            End If 
        End If 
    End Sub 

    Hope it helps

    Cheers

    Shasur

     

     

     

     


    http://www.vbadud.blogspot.com
    • Marked as answer by Tim Li Monday, February 02, 2009 9:37 AM
    Wednesday, January 28, 2009 8:41 AM