0

I have a Userform with a multipage object. In one of pages there is a textbox object where I want to add a placeholder when Enter event is not detected. Problem is I'm not figure out how to make reference to textbox from Enter and Exit events due to I have a multipage structure.

I tried to adapt the following approach but it works only for a Userform without Multipage structure. Got it here: Text box prompt text in Excel VBA

Private Sub TextBox1_Enter()
    TB_enter ActiveControl.Name
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
    TB_exit ActiveControl.Name
End Sub

Sub TB_enter(TB_name)
    If Len(Me.Controls(TB_name).Tag) = 0 Then
        Me.Controls(TB_name).Tag = Me.Controls(TB_name).Value
        Me.Controls(TB_name).Value = vbNullString
    End If
End Sub
Sub TB_exit(TB_name)
    If Len(Me.Controls(TB_name).Value) = 0 Then
        Me.Controls(TB_name).Value = Me.Controls(TB_name).Tag
        Me.Controls(TB_name).Tag = vbNullString
    End If
End Sub

Here is a video that shows how to do it when the Userform don't have a Multipage structure: https://www.youtube.com/watch?v=yJ4fnw1zmGU

Setting up properties Tag and Text of textbox I get the placeholder if use a properly Forecolor (&H8000000) but I can't make it works dynamically, that means: delete placeholder text when Enter event occurs and if lenght (Len) of the string inside textbox is zero when Exit event occurs must show the placeholder string again.

Any suggestions? Thanks in advance.

4
  • How is the multipage causing you issues? Do you receive an error message or just 'nothing' happens? Also what happens when you step through the code? Commented Aug 1, 2019 at 14:50
  • also you might want to test using the SelectedItem property? Might help? Commented Aug 1, 2019 at 14:55
  • @SamuelEverson Just 'nothing happens'. If you make reference to Enter and Exit events with the name of the textbox then nothing happens. It's look like that you need to make reference to the textbox page first and then to textbox but I don't know how. Commented Aug 1, 2019 at 18:42
  • @SamuelEverson How can I do to create an Enter or Exit event of a textbox with SelectedItem property? Commented Aug 1, 2019 at 18:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.