I have created form resembling a standard dialog box where some enters there name into a text box and then hits 'ok' taking them to the main form..On this form I need to get the name that is typed into the text box to be displayed on the main form.

How do I go about doing this?

The standard dialog box form is named frmInput and the text box is named txtName
The label where the Name is be displayed on the main form (frmSquare) is named Label1

Several ways in which to do this and here are three...

1.) (Pass) Add a module and declare a public string variable and when user hits ok, you set the variable with the string you want. Then when the other form loads, that form retrieves the value and displays it in your label.

'module code
Option Explicit

Dim MyString As String
'------------
'form that accepts input
Option Explicit

Private Sub Command1_Click()
MyString = Text1.Text
Form2.Show
Unload Me
End Sub
'--------------
'main form that displays input
Option Explicit

Private Sub Form_Load()
Label1.Caption = MyString
End Sub

2.) (Push) From the form that recieves the input you can directly set the value of the label.

Option Explcit

Private Sub Command1_Click()
Load Form2
Form2.Label1.Caption = Text1.Text
Form2.Show
End Sub

3.) (Pull) When user clicks OK you hide the input form, show the display form and pull the information from the input form.

'input form
Option Explicit

Private Sub Command1_Click()
Me.Hide
Form2.Show
Unload Me
End Sub
'-----------------
'Display Form
Option Explicit

Private Sub Form_Load()
Label1.Caption = Form1.Text1.Text
End Sub

Good Luck

I think that code is too long to handle , may be this will help you !!

Private Sub Command1_Click()
Me.Hide
Form2.Show
Form2.Label1.Caption = Text1.Text
End Sub

Try it
Best Of Luck

Hey V, if you look closely you will see that is the same code that I labeled as 2.) (Push)... and if you read my post that is not just one example but three...

I agree with vb5prgrmr, Sample 1 (PASS) is the easiest and safest way of having the name available for ANY form...

Thank you for all the help..I was able to figure it out


vb5prgrmr: the third code was able to work. Thank you :]

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.