Excel userform with predefined text

malveiro

New Member
Joined
May 13, 2015
Messages
32
Hello

I have an userform that is working well , now , i'm struggling to make this :
In textbox13 , i want it to have a predefined text but editable and only if the textbox1 and textbox12 have value/text like this

TextBox13.Text = "Reporta que a impressora" & " " & TextBox1.Text & " " & TextBox12.Text , with the cursor at the end , with the possibily to write anything after that

already tried with textbox afterupdate , tried to make in the userform initialize with no success

when i tried with the afterupdate , the text appears , but when i clicked , it dissapears

Is there any way to make this ?

Thanks in advance
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Assuming that you are using TextBox12_AfterUpdate() to put the text into TextBox13
then this should work
VBA Code:
Private Sub TextBox13_Enter()
    With Me.TextBox13
        .EnterFieldBehavior = 1
        .SelStart = Len(.Text)
    End With
End Sub
 
Upvote 0
Assuming that you are using TextBox12_AfterUpdate() to put the text into TextBox13 then this should work
VBA Code:
Private Sub TextBox13_Enter()
    With Me.TextBox13
        .EnterFieldBehavior = 1
        .SelStart = Len(.Text)
    End With
End Sub
If I have interpreted the op correctly, that won't prevent your code from writing to Textbox13 if Textbox1 is not filled in.
only if the textbox1 and textbox12
So maybe more like
VBA Code:
If Textbox1 <> "" And Textbox12 <> "" Then
   Textbox13 = "your phrase here" & Textbox1 & " " & Textbox12
   Textbox13.SelStart = Len(Textbox13)
End If
Where it goes would depend on how and when you want it to work.
 
Upvote 0
If I have interpreted the op correctly, that won't prevent your code from writing to Textbox13 if Textbox1 is not filled in.

So maybe more like
VBA Code:
If Textbox1 <> "" And Textbox12 <> "" Then
   Textbox13 = "your phrase here" & Textbox1 & " " & Textbox12
   Textbox13.SelStart = Len(Textbox13)
End If
Where it goes would depend on how and when you want it to work.
Thank you both , this worked , but , if i add some text in textbox13 to the predefined , example : you phrase here , it's not a question , and if i change to other textbox and return to textbox13 , it will display your phrase here , the text i added ( it's not a question ) , dissappear
 
Upvote 0
I understand why that happens but I don't understand the rest of your post. Are you asking a question or asking for assistance or neither?
If you use a textbox event such as Enter, each time you enter it the value gets changed to what the code tells it to be. If you want to be able to go in, out and back into the textbox and not change what's there, you need another IF block/statement or another AND condition. Perhaps
VBA Code:
If Textbox1 <> "" And Textbox12 <> "" And Textbox13 = "" Then
   Textbox13 = "your phrase here" & Textbox1 & " " & Textbox12
   Textbox13.SelStart = Len(Textbox13)
End If
or
VBA Code:
If Textbox1 <> "" And Textbox12 <> "" Then
   If Textbox13 = ""  Then Textbox13 = "your phrase here" & Textbox1 & " " & Textbox12
   Textbox13.SelStart = Len(Textbox13)
End If

Either of those would put the cursor at the end of the text when you enter the control. If you don't want that to happen when there is already something in the control then that has to be coded also.
 
Upvote 0
Perhaps this
VBA Code:
Private Sub TextBox13_Enter()
    With Me.TextBox13
        .EnterFieldBehavior = 1
        If Len(.Text) = 0 Then
            If TextBox1 <> "" And TextBox12 <> "" Then
               .Text = "your phrase here " & TextBox1 & " " & TextBox12
            End If
       End If
    End With
End Sub
 
Last edited:
Upvote 0
I understand why that happens but I don't understand the rest of your post. Are you asking a question or asking for assistance or neither?
If you use a textbox event such as Enter, each time you enter it the value gets changed to what the code tells it to be. If you want to be able to go in, out and back into the textbox and not change what's there, you need another IF block/statement or another AND condition. Perhaps
VBA Code:
If Textbox1 <> "" And Textbox12 <> "" And Textbox13 = "" Then
   Textbox13 = "your phrase here" & Textbox1 & " " & Textbox12
   Textbox13.SelStart = Len(Textbox13)
End If
or
VBA Code:
If Textbox1 <> "" And Textbox12 <> "" Then
   If Textbox13 = ""  Then Textbox13 = "your phrase here" & Textbox1 & " " & Textbox12
   Textbox13.SelStart = Len(Textbox13)
End If

Either of those would put the cursor at the end of the text when you enter the control. If you don't want that to happen when there is already something in the control then that has to be coded also.
I just found a way , i created a button , call Update , each time , it updates the textbox , Thank you to all
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top