+ Reply to Thread
Results 1 to 12 of 12

Transfer data between Userform.

  1. #1
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Transfer data between Userform.

    Hello.

    I am trying to transpher data between two userform.

    The Idear, To store information within a list box on a userform and select what list items "information" is to be copyied to another useform's Textbox.

    To have the 1st userform with a Text Box and one Button. When the user click the button the userform containing the listbox " information" is displayed. On this form the user can select an item "Information" that they want to be transphered into the other useform's textbox. (any information that is going into the textbox must only be added to the textbox information as a new line)

    Here is what i though, Though i cant keep the variable like this.

    Userform 1
    Please Login or Register  to view this content.
    Userform 2
    Please Login or Register  to view this content.
    The reason behind this, alot of the time the same thing will go into this textbox. So instead of retyping it all the time have the second userform to store various repetive data the user can then select the relevent once..

    Cheers.
    Last edited by D_Rennie; 10-30-2009 at 10:52 AM.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Transpher data between Userform.

    You mentioned that ListBox2's listbox is multi-select. In that case the .ListIndex property can't be used.
    I'd use code like this.

    in UserForm1
    Please Login or Register  to view this content.
    in UserForm2
    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Transpher data between Userform.

    Try this:

    Userform1:
    Please Login or Register  to view this content.
    Userform2:
    Please Login or Register  to view this content.

    Edit: If, as Mike said, your listbox is Multiselect, you will need to implement a loop as he did!
    Remember what the dormouse said
    Feed your head

  4. #4
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Transpher data between Userform.

    Thanks mike that will seam to do.

  5. #5
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Transpher data between Userform.

    Thankyou Romperstomper.

    Quite a nice way to use the show hide and unload. This works aswell though it didnot like to dim the userform.
    ..............


    There is one thing that i have just noticed that may stop me from using a listbox.
    Some of the information that i want to put into the listbox will need new lines, so i would want to have one listitem displayed in the style
    This is the
    1st selectable line of infromation
    avabile in the listbox.

    without having this it makes the list strings very hard to read.
    ,,

    Maby somethink like one listbox to chose a catagory and display all catagory item within a mulitline textbox.
    Then have the user highlight a section they want Copy that to the Clip Board Ready for pasting into the other form.
    Just an idear, its the copy paste part that will clench me here.
    ..

    Im a little messy on what direction to take it.
    Ill look into using the list box as a selector and a textbox next to it as an way of previewing the whole string maby.

    Cheers Both for solving the original question.

  6. #6
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Transpher data between Userform.

    I was thinking about it. It might be best to not tie the two forms together.
    Make a function that returns the value chosen from UserForm2.

    In a normal module
    Please Login or Register  to view this content.
    In UserForm1
    Please Login or Register  to view this content.
    In UserForm2
    Please Login or Register  to view this content.
    The whole purpose of UF2 is to return the user selected values. That purpose does not depend on UF1. Let UF1 worry about what to do with the user selected value. Let UF2 "concentrate" on its task of returning the user's selections. Don't mix 'em up.

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Transpher data between Userform.

    Quote Originally Posted by D_Rennie View Post
    it didnot like to dim the userform.
    The Dim statement would depend on the name of your userform. I assumed Userform2 from your post. It is better to treat userforms as a class (since they are) than use the default instance.

  8. #8
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Transpher data between Userform.

    There is some example of multiline listbox's around for other programing backgrounds.

    For example http://www.codeguru.com/cpp/controls...cle.php/c2291/ C++

    http://www.codeproject.com/KB/combob...linlisbox.aspx VB.NEt

    Does anyone know if simlar things have been done in VBA.

    Cheers

  9. #9
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Transpher data between Userform.

    RS All the names where correct in the code though i get error 91 "with Bock"... If i dim as obj or var and set frm = userform2 it will show the form though get runtime error -241######, Automation error on If frm.ListBox1.ListIndex <> -1 Then

    This is on a 2007 version if that makes a diffrence.

    Cheers
    Last edited by D_Rennie; 10-30-2009 at 11:26 AM.

  10. #10
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Transpher data between Userform.

    Ah, sorry - I missed a line out when typing. The userform1 code should be:
    Please Login or Register  to view this content.

  11. #11
    Valued Forum Contributor
    Join Date
    05-14-2009
    Location
    gold coast
    MS-Off Ver
    Excel 2007
    Posts
    843

    Re: Transpher data between Userform.

    yep thats the one.

    Any idears on the lisbox display or other methods.

  12. #12
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Transpher data between Userform.

    Depends on your data. I'd probably go with something like what you suggested - a listbox containing a brief piece of text and a label or textbox alongside so that each item you select has its full text displayed. I'd probably make the listbox single select only and have an add button to add the selected item to a textbox. Then the OK button returns to form 1 that then writes the textbox value to its own textbox.
    Having said that, this sounds an awful lot like it ought to be in a database app...

+ 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