-
Transfer the TextBox.Value from one Form to another
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
-
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]
[vba]
Dim frm as Userform2
Set frm = New Userform2
set frm.TextboxVariable = Me.Controls("asset")
[/vba]
then in Userform2
[vba]
Me.Textboxvariable.Value = "some text here"[/vba]
-
Hi Aflatton
thanks for your reply.
In UserForm2 I have now a public Variable, which is called Asset.
[VBA]Public asset As String[/VBA]
Then after the query execution it gets a value:
[VBA]asset = rs2(0).Value[/VBA]
But I didn't get it, how to transfer it to the textbox of the UserForm1?
-
The variable should be a Textbox variable, not a String.
-
try this
assuming
userform1 name = userform1
testbox name=textbox1
code on userform2
[vba]
userform1.textbox1.text=rs(0)
[/vba]
-
Also consider a multi-page userform. It looks often looks better than switching between forms.
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules