Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

enter data into text box on a different form

Status
Not open for further replies.

MalekTaus

Programmer
Nov 5, 2007
10
US

I was wondering if anyone know of a way to enter information from one form onto another form.

The situation is thus:

I have a main form with textboxes on it however one text box is a compilation of several numbers, so I created another form in order enter in those numbers. I then pass this value into a public variable. What I want to be able to do is when I close the second form automatically enter that data in the variable into the correct textbox on the first form.
 




Hi,

"one text box is a compilation of several numbers"

A TextBox is for user entry.

Doe the user get to CHANGE the "compilation of several numbers?"

Skip,

[glasses] When a diminutive clarvoyant had disappeared from detention, headlines read...
Small Medium at Large[tongue]
 
You could use custom events. The framework:
1. The second (SuppForm) form:
- declare public event,
- raise the declared event when you close form, data is proper and you want to update the main form.
2. Main form (MainForm):
- declare withevents variable as SuppForm,
- instantiate it and show,
- handle SuppForm events (update text).

Sample code (transfer textbox => label):
Code:
Private WithEvents xForm As SuppForm

Private Sub UserForm_Click()
Set xForm = New SuppForm
xForm.Show
End Sub

Private Sub xForm_CloseForm()
Me.Label1.Caption = xForm.TextBox1.Text
End Sub
Code:
Public Event CloseForm()

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
RaiseEvent CloseForm
End Sub

combo
 
That would be one way. I would like the answer to Skip's question.

"What I want to be able to do is when I close the second form automatically enter that data in the variable into the correct textbox on the first form."

If the data on FormA is a compilation of data on FormB, if there is no user input, then use a Label, not a textbox. Textboxes are for user input.

Userform1:

one label: lblMush_It_Together
two commandbuttons: SubForm and Exit

Code:
Sub cmdExit_Click
   Unload Me
End Sub

Sub cmdSubForm_Click()
   Userform2.Show
End Sub

Userform2:

three textboxes: Textbox1, Textbox2, Textbox3
one commandbutton: cmdMush_Exit
Code:
Sub cmdMush_Exit_Click()
  Userform1.lblMush_It_Together.Caption = _
      TextBox1.Text & TextBox2.Text & TextBox3.Text
  Unload Me
End Sub

The commandbutton on the second userform, concatenates the three textboxes (on userform2), dumps that into the Label on userform1, and unloads.

You could use a public variable, but it is not - at least as you have stated it - required.

The point being, is that if the compilation does NOT require further user input, then do NOT use a textbox for it. Use a Label.


faq219-2884

Gerry
My paintings and sculpture
 
Thanks guys I will use some of your examples as soon as I get the chance however I have been sidetracked on a different project for the moment.
 
BTW,

Yes, the user enters the different data being compiled from a paper report.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top