Consulting

Results 1 to 17 of 17

Thread: Solved: copy data from one userform to another

  1. #1
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location

    Solved: copy data from one userform to another

    hi experts

    Need a macro that well copy data from Userform frmform1 to Userform frmform2 if the user know that the two details are the same.

    i.e. if the Site A Address details in form frmform1 are the same as Landlord Address then the user can click the macro button in form frmform2 "Copy Address Details" and these would be populated into the Landlord address field.

    i have not yet set up a button to open up the user form from the fornt page of the worksheet....as yet.

  2. #2
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    If userform2 is opened from a button in userform1 for example using the "Next" button leaving both userforms open at the same time then you could use something like...

    UserForm2.txtPostalCodeA.Value = UserForm1.txtPostalCode.Value

    for each textbox you want to copy over.

    Hope this helps
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  3. #3
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    Hi

    Both form are not open at the same time on next click the first form is closed.....

  4. #4
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    tried and tested the above getting a compile error: method or data member not found

  5. #5
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Pete, are the Site A Address details in form frmform1 added to the worksheet before/when frmform1 is closed? If so you can retrieve the info from the range of the sheet.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  6. #6
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    Hi Lucus

    What happens is i add the siteA form 1 details in then navigate to for 2 using the next button. if they are the same then i wish to click a macro to copy field data accross as opposed to re-typing it all out again....

  7. #7
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Well, your userforms and explainations are confusing so just to pin you down.....

    On userform1(please be specific) you want the text in textbox txtBuildingName to be transferred to userform2 into textbox txtBuildingNameA

    when you hit the Next button or when you hit the button on userform 2 that says "Copy address details" Which one do you want to happen.

    Is that correct so far?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  8. #8
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    Hi Lucus

    On userform1(please be specific) you want the text in textbox txtBuildingName to be transferred to userform2 into textbox txtBuildingNameA - yes

    when you hit the Next button or when you hit the button on userform 2 that says "Copy address details" Which one do you want to happen. - when i hit the copy address details button and only then and not on clicking the next button.




    Is that correct so far?

  9. #9
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    On userform 1 when you hit the finish & save button is the data in textbox txtBuildingName supposed to be added to the sheet1 range M-AA row 25?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  10. #10
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    hi Lucus

    On userform 1 when you hit the finish & save button is the data in textbox txtBuildingName supposed to be added to the sheet1 range M-AA row 25? - NO

    This data is going somewhere else.......

  11. #11
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    I Need to know where......is it a secret?
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  12. #12
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    LOL..... Secret?, Sorry had to laugh.

    You could make it very simple if you could keep everything in one workbook then maybe export it after you have completed the tasks with the forms. See example.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  13. #13
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    Hi georgiboy, your method leaves both userforms open which is an option. Another is to use a global variable but I was just looking for a simple solution as this project seems to be in the very earliest stages, ie if the data is placed in the worksheet....just retreive it from there.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  14. #14
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    Lucas,

    I see where you are coming from with taking the data from where it is put and keeping it simple. This is why i have suggested keeping all in one workbook then exporting at a later point in the code (when the second userform is closed), it may only take adding one more worksheet to hold the data until it is time to move it to another workbook. I suppose there is a few ways to achieve this and i am interested to see wich route is taken. As your knowledge of VBA is far greater than mine i will leave it to you.

    I like to see multiple inputs from people on this forum as it will normally will end up with the most suited solution, i have learned all i know from this forum and i will continue to poke my nose in all the time i am allowed to do so. I am on my third glass of wine now so i should probably go.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  15. #15
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    georgiboy,
    Please continue to contribute when you feel like you can add to the conversation......the more the merrier and often many ideas come from such conflaberations......

    I'm jelous of the wine drinking.....it's still early here.

    I was just continuing the conversation so don't think it was criticizm please.
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

  16. #16
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,198
    Location
    I was just continuing the conversation so don't think it was criticizm please.
    I dont, trust me all is well.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved
    Click here for a guide on how to upload a file with your post

    Excel 365, Version 2403, Build 17425.20146

  17. #17
    VBAX Tutor
    Joined
    Aug 2007
    Posts
    294
    Location
    hi georgiboy vbmenu_register("postmenu_172449", true);

    the example workbook works prefect thanks for the excellent feedback....

Posting Permissions

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