+ Reply to Thread
Results 1 to 12 of 12

Pass variables between user forms.

  1. #1
    Registered User
    Join Date
    08-06-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    35

    Pass variables between user forms.

    Hello,

    Can someone help me how to pass variables between two userforms, for example pass the value of a date (Calendar userform) to another userform (label).

    Any help will be very grateful.

    Regards

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Pass variables between user forms.

    Hello Francisco Sousa,

    You can data via Global variables in a VBA module or directly between the UserForms. To pass a value directly between forms, both forms must be loaded into memory by using either the Show method of the UserForm or by calling the VBA Load function.

    Most Calendars copy the date to the active cell of the worksheet. What is the name of the control on the Calendar that displays the date?
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Registered User
    Join Date
    08-06-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Pass variables between Userforms.

    Hello,

    Thanks for your help, I attached an Excel file if you want to help me. How do I pass the day (variable our more others variables) from the Userfom Calendar to add in a label in another Userform.

    Best Regards
    FS
    Attached Files Attached Files

  4. #4
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Pass variables between Userforms.

    Try this.

    Please Login or Register  to view this content.
    Click the * Add Reputation button in the lower left hand corner of this post to say thanks.

    Don't forget to mark this thread SOLVED by going to the "Thread Tools" drop down list above your first post and choosing solved.

  5. #5
    Registered User
    Join Date
    08-06-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Pass variables between Userforms.

    Hello Skywriter

    I made the same test like your suggestion previously, but when I call the userform FolhaCaixa1 the variable "data" declared as Public in userform Calendario goes empty. Remember that I have two useforms (Calendario and Folhacaixa1) and my problem is that I can't see the value of "data" variable in the userform Folhacaixa1

    For instance, in portuguese the word "data" means date.

    Best regards
    FS

  6. #6
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Pass variables between user forms.

    So the way this works is I click the button Call Calendar on the sheet Value. The calendar pops up, I click on a date and the other form pops up with the date I chose in the big label at the top. Try it.
    Attached Files Attached Files

  7. #7
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: Pass variables between user forms.

    Hi skywriter
    I tried your file at post # 6 and I got this error
    "Couldn't load an object because it is not available on this machine"
    Is there specific reference to be used ?
    Another point
    In toolbox I tried right click >> Additional Control , nothing appeared as before
    Is there anything wrong with my office?
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  8. #8
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Pass variables between user forms.

    Quote Originally Posted by YasserKhalil View Post
    Hi skywriter
    I tried your file at post # 6 and I got this error
    "Couldn't load an object because it is not available on this machine"
    Is there specific reference to be used ?
    Another point
    In toolbox I tried right click >> Additional Control , nothing appeared as before
    Is there anything wrong with my office?
    Hi YasserKhalil

    I have no problems with this file, it's his file, I just added some code shown above.

    I see you both have Excel 2007, so I changed the file to xlsm, you can try that one, maybe it will help.
    Attached Files Attached Files
    Last edited by skywriter; 05-10-2015 at 10:51 AM.

  9. #9
    Registered User
    Join Date
    08-06-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Pass variables between user forms.

    Hello,

    It works, and I come to thank you all again for your invaluable help and your readiness.

    But I found other way that works, the code below shows how it was done;

    This is the code on the Calendario userform:
    Please Login or Register  to view this content.

    And this is the code on FolhaCaixa1 userform, when the value is passed on UserForm_Initialize()
    Please Login or Register  to view this content.
    And it's work.

    Thank you once again.
    Regards,
    FS

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

    Re: Pass variables between user forms.

    You can remove this line:
    Please Login or Register  to view this content.
    since you aren't actually using that variable at all.
    Remember what the dormouse said
    Feed your head

  11. #11
    Registered User
    Join Date
    08-06-2010
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    35

    Re: Pass variables between user forms.

    Thanks for the advice. I removed it, and works.

    A Guru is always an Guru.

    Regards
    FS

  12. #12
    Forum Expert skywriter's Avatar
    Join Date
    06-09-2014
    Location
    USA
    MS-Off Ver
    2016
    Posts
    2,760

    Re: Pass variables between user forms.

    Thanks for sharing the tag code, I will remember that.

    If your original request is fulfilled please click the Thread Tools drop down box above your first post and choose solved.

    If you are happy with my help, please consider clicking the add reputation button in the lower left hand corner of this post.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Excel 2007 : Cant pass variables properly
    By grizzlypete44 in forum Excel General
    Replies: 4
    Last Post: 12-01-2011, 09:51 AM
  2. cant pass variables between controls
    By grizzlypete44 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-30-2011, 03:14 PM
  3. Logon Box - User / Pass - Unique actions per user.
    By CVinje in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-04-2009, 07:41 AM
  4. [SOLVED] Pass environmental variables?
    By Gunkie in forum Excel General
    Replies: 2
    Last Post: 03-07-2005, 07:06 PM
  5. Pass variables value to Shell
    By wpw3 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-07-2005, 12:06 PM

Tags for this Thread

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