Consulting

Results 1 to 6 of 6

Thread: Transfer the TextBox.Value from one Form to another

  1. #1
    VBAX Regular
    Joined
    Dec 2011
    Posts
    58
    Location

    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

  2. #2
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    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]
    Be as you wish to seem

  3. #3
    VBAX Regular
    Joined
    Dec 2011
    Posts
    58
    Location
    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?

  4. #4
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    The variable should be a Textbox variable, not a String.
    Be as you wish to seem

  5. #5
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    try this

    assuming
    userform1 name = userform1
    testbox name=textbox1

    code on userform2

    [vba]
    userform1.textbox1.text=rs(0)
    [/vba]

  6. #6
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    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
  •