Calling a New Form and auto populating the text fields

thebadger

New Member
Joined
Mar 8, 2004
Messages
22
I have two user forms - one of which enables the user to search for a particular item. Providing this item is found (using find) I would like to be able to then show another form - prepopulated with information relating to items searched upon in the first form.

I have some code which ensures the 'search' item is found - this then calls the next form using form2.show. I was then going to assign values to the text fields using the activecelloffset comand based upon the cell found in the first form.

My problem is that I can call the second form but I cannot get anything to populate in the text fields.

I was wondering if these text fields need to be defined in the code of the first form - or if there is something to be added to an event procedure on the second from that will then show these values ?
 

Some videos you may like

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

SIXTH SENSE

Well-known Member
Joined
Oct 29, 2003
Messages
1,883
Hi!
you may add this lines on the on activate event of the second form.
Code:
Form2.textbox1.text=someinfo1
Form2.textbox2.text=someinfo2
'and so on and so forth.
 

parry

MrExcel MVP
Joined
Aug 20, 2002
Messages
3,355
Hi, you need to use the full object identifiers to the form your calling. So instead of TextBox1.Text put UserForm2.TextBox1.Text to identify that box. Use the Load statement to put the other form into memory then add the values to the boxes then show the form.

Code:
Private Sub CommandButton1_Click()
Load UserForm2  'put form into memory so boxes can be filled in
UserForm2.TextBox1.Text = ActiveCell.Value
UserForm2.TextBox2.Text = ActiveCell.Offset(0, 1).Value
UserForm2.TextBox3.Text = ActiveCell.Offset(0, 2).Value
UserForm2.Show 'show form
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,123,383
Messages
5,601,316
Members
414,441
Latest member
KellyTheKid

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
Top