• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Textbox Text Disappear on Text Entry Excel VBA

@Kmahraz the code that vletm gave is the only way to make the "Please Enter Name Here" blank. Problem is that there is no code to check which textbox you clicked in & target that specific text box. Easier way is why not twin it with the checkbox you use to enable the textboxes. That way when you tick the checkbox, all the textboxes will enable & all will go blank. Have modified sample code for you for CheckBox5.

Had to change "TxtT" to "TxtTP" as what I've done is added a secondary piece of code that adds the "Please Enter Name Here" if the TextBox was blank. So if I hadn't changed it, It would write stuff in Cost & Qty as well

Code:
Private Sub CheckBox5_Click()
'Enable Texboxes for the T. Fittings
Dim cCont As Control

If CheckBox5 = True Then

    Application.EnableEvents = False
   
    For Each cCont In Me.MultiPage1.Pages("Page2").Controls
        With cCont
            If .Name Like "TxtTP" & "*" Then
                .Object.Enabled = True
                If .Object.Text = "Please Enter Name Here" Then
                .Object.Text = ""
                Else
                End If
                .Object.ForeColor = RGB(0, 0, 0)
            End If
        End With
    Next
   
    Application.EnableEvents = True

Else

    Application.EnableEvents = False
   
    For Each cCont In Me.MultiPage1.Pages("Page2").Controls
        With cCont
            If .Name Like "TxtTP" & "*" Then
                .Object.Enabled = False
                If .Object.Text = "" Then
                    .Object.Text = "Please Enter Name Here"
                Else
                End If
                .Object.ForeColor = RGB(165, 165, 165)
            End If
        End With
    Next
   
    Application.EnableEvents = True
   
End If
End Sub
 
Hi @chirayu
Thank you so much, I like the idea of having the check box control the textbox this will make thing easier. I will give it a try and let you know how it went.

Just wanted to take a moment to thank again both of you @chirayu and @vletm you guys are great.

Regards,
Mahraz
 
@chirayu
There are many ways to make things ...
This works only with activated textbox, not 'group of textboxes', as asked.
Every textbox have own Macro like '...TxtWPN1_Enter'.
Every textbox knows own 'name'.
That name takes to next Macro, which change textcolor and empties its value.
There can still be missing features, like if textbox stays empty ...
 
@chirayu
I agree with @vletm, my initial code that I provided initially did handle the option if textbox stays empty, If user doesn't enter any text in textbox it should default to the value "Please Enter Name Here".
Both solutions have Pro and Cons.

Thank you!

Mahraz
 
@NARAYANK991
Hi
Just wondering if you may have another solution to make the text disappear when the user click on the text boxes and reappear if no entry is made, the I should apply to all text boxes ?
Thanks
Mahraz
 
Hi Karim ,

As vletm has already mentioned , all these objects are having their own event driven procedure ; combining all of these into one procedure may not be possible , though I cannot be sure of this.

Till such time someone else can point you in a different direction , I think the only option is to have 30 different event procedures , one for each textbox , for entry into the textboxes , and 30 different event procedures , one for each textbox , for exit from the textboxes.

Narayan
 
@Kmahraz as stated by Narayank in his post & me in my last post. Theres no way to check which textbox you clicked in unless you manually code for all textboxes (of which you have many). thats why I gave the solution of twinning with checkbox so that all can be done in one go.
 
@chirayu
Agreed, I believe a misread the explanation that Narayan provided, I was able to use your suggested solution and everything is working great.
Thank you ALL for the great help!

Best,
Mahraz
 
Back
Top