none
regarding flash textbox userform vba RRS feed

  • Question

  • dears

    good greeting

    how can flash the textbox inside userform vba in case of acheiving some condition

    for exaple if textbox1 = "mentioned text"

    regards.................

    Wednesday, March 14, 2018 7:52 PM

Answers

  • Hi TAREK SHARAF,

    You had asked,"how can flash the textbox inside userform vba in case of acheiving some condition"

    Do you mean you want to perform validation check based on custom condition and if condition gets wrong then blink the textbox?

    If yes, Try to refer example below.

    In example below, If Textbox is empty then It will change the label and blink.

    Private Sub CommandButton1_Click()
    Dim i As Long
        If Me.TextBox1 = "" Then
            Me.Label1.Caption = "Textbox Cannot be blank...."
            Me.Label1.ForeColor = vbRed
                For i = 1 To 3
                    TextBox1.BackColor = vbRed
                    Application.Wait (Now + TimeValue("0:00:1"))
                    TextBox1.BackColor = vbGreen
                    Application.Wait (Now + TimeValue("0:00:1"))
                    TextBox1.BackColor = vbWhite
                
                Next i
                    
        End If
    End Sub
    

    Output:

    As Blinking is not get captured in screen record I post the snapshot of it.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by TAREK SHARAF Thursday, March 15, 2018 5:46 AM
    Thursday, March 15, 2018 2:20 AM
    Moderator
  • Hi TAREK SHARAF,

    You had mentioned that,"i want the flashing process to repeat continously without stop".

    To repeat the process you need to loop infinitely. Which is not recommended.

    By that way It is possible that Application can get hanged.

    If loop runs continuously then it is just increase the over head.

    So I suggest you to chnage the value of loop line below.

         For i = 1 To 20
    

    For demo purpose, I only loop through 3 times, you can chnage it as per your requirement.

    Also try to exit the loop, If user try to click textbox to insert value.

    So that when he enter the value then he can properly see the value.

    If possible then do not blink the textbox continuously and show the msgbox to user to insert value in textbox.

    Then set the focus to that textbox and if user try to click somewhere else and if textbox is still empty then you can keep the focus on that textbox to force the user to input value.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by TAREK SHARAF Sunday, March 18, 2018 6:17 PM
    Thursday, March 15, 2018 7:48 AM
    Moderator

All replies

  • Hi TAREK SHARAF,

    You had asked,"how can flash the textbox inside userform vba in case of acheiving some condition"

    Do you mean you want to perform validation check based on custom condition and if condition gets wrong then blink the textbox?

    If yes, Try to refer example below.

    In example below, If Textbox is empty then It will change the label and blink.

    Private Sub CommandButton1_Click()
    Dim i As Long
        If Me.TextBox1 = "" Then
            Me.Label1.Caption = "Textbox Cannot be blank...."
            Me.Label1.ForeColor = vbRed
                For i = 1 To 3
                    TextBox1.BackColor = vbRed
                    Application.Wait (Now + TimeValue("0:00:1"))
                    TextBox1.BackColor = vbGreen
                    Application.Wait (Now + TimeValue("0:00:1"))
                    TextBox1.BackColor = vbWhite
                
                Next i
                    
        End If
    End Sub
    

    Output:

    As Blinking is not get captured in screen record I post the snapshot of it.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by TAREK SHARAF Thursday, March 15, 2018 5:46 AM
    Thursday, March 15, 2018 2:20 AM
    Moderator
  • dear mr / deepak

    i want the flashing process to repeat continously without stop

    regards..........

    Thursday, March 15, 2018 5:48 AM
  • Hi TAREK SHARAF,

    You had mentioned that,"i want the flashing process to repeat continously without stop".

    To repeat the process you need to loop infinitely. Which is not recommended.

    By that way It is possible that Application can get hanged.

    If loop runs continuously then it is just increase the over head.

    So I suggest you to chnage the value of loop line below.

         For i = 1 To 20
    

    For demo purpose, I only loop through 3 times, you can chnage it as per your requirement.

    Also try to exit the loop, If user try to click textbox to insert value.

    So that when he enter the value then he can properly see the value.

    If possible then do not blink the textbox continuously and show the msgbox to user to insert value in textbox.

    Then set the focus to that textbox and if user try to click somewhere else and if textbox is still empty then you can keep the focus on that textbox to force the user to input value.

    Regards

    Deepak


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by TAREK SHARAF Sunday, March 18, 2018 6:17 PM
    Thursday, March 15, 2018 7:48 AM
    Moderator
  • dear mr/deepak

    it worked well 

    thanks alot for your help and support brother

    accept my greeting

    Sunday, March 18, 2018 6:18 PM
  • Hey Pal,

    Thank you so much for the help 

    I really appreciate that 

    Friday, April 10, 2020 1:40 PM