PDA

View Full Version : Transfer the TextBox.Value from one Form to another



lionne
12-28-2011, 01:51 AM
Hi everybody,

I've got an issue, that makes me unable to sleep at night, because I can't solve it.. tried many things, but nothing worked...

I have a list of some parameters (TextBox Names), based on which I generate the Excel Form (UserForm1) for a user to fill it out.
If I have a parameter (TextBox Name) in the list called say "asset", then I add a button to the UserForm1, which is called "Find Asset". By clicking on that button, new Form UserForm2 is opened, where I have 3 ComboBoxes - search criteria. Then, by pressing OK, my DB Query looks for an asset. If the value is found, I need to transfer it to a UserForm1.asset TextBox. Exactly this step I don't know how to do. This doesn't work:

UserForm1.asset.Value = rs(0).Value 'rs is a RecordSet

Is it possible to give the rs(0).Value to a TextBox field of UserForm1 at all?

Lionne

Aflatoon
12-28-2011, 03:10 AM
I would suggest that you add a public Textbox variable to the second userform (or preferably, use a property procedure), and then assign the textbox you want populated to that variable when you show the second form - for example:
[code in Userform1]

Dim frm as Userform2
Set frm = New Userform2
set frm.TextboxVariable = Me.Controls("asset")


then in Userform2

Me.Textboxvariable.Value = "some text here"

lionne
12-28-2011, 04:03 AM
Hi Aflatton
thanks for your reply.
In UserForm2 I have now a public Variable, which is called Asset.
Public asset As String
Then after the query execution it gets a value:
asset = rs2(0).Value

But I didn't get it, how to transfer it to the textbox of the UserForm1?

Aflatoon
12-28-2011, 04:47 AM
The variable should be a Textbox variable, not a String.

mohanvijay
12-28-2011, 05:26 AM
try this

assuming
userform1 name = userform1
testbox name=textbox1

code on userform2


userform1.textbox1.text=rs(0)

mdmackillop
12-29-2011, 12:48 PM
Also consider a multi-page userform. It looks often looks better than switching between forms.