I wish to if someone types something in a textbox that it shows up in a label..but on another form...so say in the textbox i type in "Sharpy" then "Sharpy" shows up on another form.

Dani AI

Generated

A small clean pattern: keep Form2 responsible for its own controls and expose a simple method (or property) that accepts the text. That avoids tight coupling (Form1 reaching into Form2.Label1) and makes maintenance easier if you rename controls or change the UI. and demonstrated the basic idea, and rightly noted the live-update option via Text_Change — this shows a slightly more robust approach that works for both a button click and for live updates.

' In Form2
Public Sub SetLabelText(ByVal value As String)
    value = Trim$(value)
    If value = "" Then
        Me.Label1.Caption = "(no text)"
    Else
        Me.Label1.Caption = value
    End If
End Sub
' In Form1 (button click)
Private Sub Command1_Click()
    Dim s As String
    s = Trim$(Text1.Text)
    If s = "" Then
        MsgBox "Please enter text.", vbExclamation
        Exit Sub
    End If
    Load Form2
    Form2.SetLabelText s
    Form2.Show vbModal
End Sub

If you need multiple independent windows, create a new instance instead of using the default form object:

Dim f As Form2
Set f = New Form2
f.SetLabelText Trim$(Text1.Text)
f.Show

Tips: use Text_Change only when you want updates on every keystroke (it fires very frequently); guard calls with checks like If Form2.Visible Then to avoid errors. Prefer the setter approach over direct control access for clearer code and fewer surprises when forms load/unload.

Recommended Answers

All 6 Replies

thought this could help;
Private Sub Command1_Click()
Form2.Show
Form2.Text1.Text = Form1.Text1.Text
End Sub
Form1 has 2 controls, text1 and command1

doesn't help me sorry, I want it so when you type in a word in the Text Box and click on a button then it will show up in the next form

Change this line:
Form2.Text1.Text = Form1.Text1.Text

to this:
Form2.Label1.Caption = Text1.Text

Or did you not want to use a command button?
You could try Text1_Change, instead of Command1_Click.

If you don't want Form2 to show at this point, then use "Load Form2" earlier, then you can Show or Hide it as you need to.

hope that helps, if not give us a little more explanation of what you want to do.

Thanks its working now

Glad I could help

try using the text1.change() event That way it is automatically change whenever you type something

public Sub text1_change()
     form1.label1.caption = trim(text1.text)
end sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.