+ Reply to Thread
Results 1 to 8 of 8

Copying TextBox entry from one UserForm to another

Hybrid View

  1. #1
    excelnut1954
    Guest

    Copying TextBox entry from one UserForm to another

    When UserForm4 comes up, the user enters data in TextBox1. When the
    user completes UserForm4, he clicks Next, and UserForm6 comes up. I
    would like the number entered in TextBox1 of UserForm4 to automatically
    populate TextBox7 of UserForm6.
    Can this be done?

    Thanks,
    J.O.


  2. #2
    Kris
    Guest

    Re: Copying TextBox entry from one UserForm to another

    excelnut1954 wrote:
    > When UserForm4 comes up, the user enters data in TextBox1. When the
    > user completes UserForm4, he clicks Next, and UserForm6 comes up. I
    > would like the number entered in TextBox1 of UserForm4 to automatically
    > populate TextBox7 of UserForm6.
    > Can this be done?
    >
    > Thanks,
    > J.O.
    >



    ' ------------------------------define this to constant somewhere
    public const CancelClicked = 0
    public const NextClicked = 1



    '----both user form code

    Option Explicit

    Private m_bResult As Boolean
    Property Get Result() As Boolean
    Result = m_bResult
    End Property

    Private Sub btnCancel_Click()
    m_bResult = CancelClicked
    Hide
    End Sub
    Private Sub btnNext_click()
    If Not ValidateUserInput() Then Exit Sub
    m_bResult = NextClicked
    Hide
    End Sub



    Private Function ValidateUserInput() As Boolean
    ValidateUserInput = False

    'if data don't fit criteria then exit function

    ValidateUserInput = True

    End Function





    ' -------------- your module code


    load UserForm4
    UserForm4.Show

    if UserForm4.Result = NextClicked then
    load UserForm6
    UserForm6.TextBox7.value = userForm4.TextBox1.value
    UserForm6.Show
    ' do something with values from UserForm6
    unload userForm6
    end if
    unload UserForm4



    -------------------------
    The clue is that data are initiated and processed in parent module not
    in user form directly.
    Initiated after loading user form , processed after returning from .show

    In general user form shouldn't interact with data which is not a part of
    user form.
    Everything can be done in parent module after hiding user form.


    Try to not have unload me in your user form and you'll see that
    everything becomes simpler.










  3. #3
    excelnut1954
    Guest

    Re: Copying TextBox entry from one UserForm to another

    I sure do appreciate your help. But, I really don't know where to put
    all this code. Some of it makes sense, but I just don't know where it
    goes. I've tried putting it all into a seperate Module, but it isn't
    right. Guess I'm not experienced enough to understand the terminology.
    Thanks,
    J.O.


  4. #4
    excelnut1954
    Guest

    Re: Copying TextBox entry from one UserForm to another

    I'm sure the code Kris entered above is correct.

    But, is there anyone who can simplify it? What I want seems do be just
    a simple Copy & Paste situation. I know that's not how this all works,
    but there has to be a simplier way to do this.

    I just want TextBox7 of UserForm6 to automatically be what was just
    entered in TextBox1 of UserForm4.

    Can anyone help?


  5. #5
    Tom Ogilvy
    Guest

    Re: Copying TextBox entry from one UserForm to another

    In a general module, put in code like

    Public myvar as String

    in Userform4 code module put in

    Sub TextBox1_Change()
    myvar = Textbox1.Value
    End sub

    In Userform6 code module

    Private Sub Userform_Activate()
    Textbox7.Value = MyVar
    End Sub

    --
    Regards,
    Tom Ogilvy


    "excelnut1954" <[email protected]> wrote in message
    news:[email protected]...
    > I'm sure the code Kris entered above is correct.
    >
    > But, is there anyone who can simplify it? What I want seems do be just
    > a simple Copy & Paste situation. I know that's not how this all works,
    > but there has to be a simplier way to do this.
    >
    > I just want TextBox7 of UserForm6 to automatically be what was just
    > entered in TextBox1 of UserForm4.
    >
    > Can anyone help?
    >




  6. #6
    excelnut1954
    Guest

    Re: Copying TextBox entry from one UserForm to another

    Thanks, Tom.
    This seems simple enough. I put the code in UserForms 4 & 6 as you
    directed.
    1 question. The 1st part of your solution:
    ***************************************
    In a general module, put in code like

    Public myvar as String
    ****************************************

    I'm still unclear on this statement. I tried putting it in a seperate
    module like this Public myvar as String()
    But, that's not correct. I put it in as a single line code in a Module
    called Sub Macro1()
    But, I don't see how the statement gets implemented. I tried calling
    this Macro1 from another Module, then calling UserForm4 to start the
    process. But, data from TextBox1 of UserForm4 still doesn't paste to
    TextBox7 of UserForm6.
    Just what do I do with the Public myvar... statement?

    I appreciate your time and patience.
    J.O.


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1