+ Reply to Thread
Results 1 to 10 of 10

Modify in Userform using a variable in a function

  1. #1
    Forum Contributor
    Join Date
    04-13-2017
    Location
    Buchares
    MS-Off Ver
    2016
    Posts
    117

    Modify in Userform using a variable in a function

    Hey guys,

    I have N userforms with variable names with X textboxes within.
    I want to create a function to call to do something to the userform with the name i desire / from where it has been called in a module.


    something like do_this (name_of_the_form, text_inserted_in_textbox, what_text_box)

    The problem is that i can't find a way to do something to a userform with a variable name. I've tried to search for it as object, error, declare it as string again resulted in an error.

    how i can reference to a Userform From String ? or something
    Attached Files Attached Files

  2. #2
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Modify in Userform using a variable in a function

    The fact that you need to do this makes me think your entire structure is flawed, but it's hard to comment further with so little information in the workbook.

    Anyway, you could use:

    Please Login or Register  to view this content.
    Rory

  3. #3
    Forum Contributor
    Join Date
    04-13-2017
    Location
    Buchares
    MS-Off Ver
    2016
    Posts
    117

    Re: Modify in Userform using a variable in a function

    This is a simple example, on the real project yeah....it's quite a mini-mess and im trying to reduce the number of rows (it's a idea)

    The code
    UserForms.Add(name_of_the_form).Label4.Caption = final_text

    Does not work ,
    Not updating the userform

  4. #4
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Modify in Userform using a variable in a function

    Is the form already open? If so, is there a reason you can't pass it as an object, rather than the name of a form?

  5. #5
    Forum Contributor
    Join Date
    04-13-2017
    Location
    Buchares
    MS-Off Ver
    2016
    Posts
    117

    Re: Modify in Userform using a variable in a function

    the form is already opened , and i am opened to any ideas.

  6. #6
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,911

    Re: Modify in Userform using a variable in a function

    How do you intend to use the function - where will you call it from, for example? Does it actually need to be a function, given that you aren't returning anything?

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

    Re: Modify in Userform using a variable in a function

    Given the name of a userform, this function will return the open userform that has that name.

    Please Login or Register  to view this content.
    To use it in your textbox getting function.

    Please Login or Register  to view this content.
    Or a textbox setting function
    Please Login or Register  to view this content.
    If you want to call one of the subs in a userform, you could use CallByName.

    But when you say that you have N userforms, my first thought is that you have way too many and I suspect that you are creating custom purpose userforms that could be cutomized at run-time rather than at design time.
    Last edited by mikerickson; 09-24-2018 at 09:29 AM.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  8. #8
    Forum Contributor
    Join Date
    04-13-2017
    Location
    Buchares
    MS-Off Ver
    2016
    Posts
    117

    Re: Modify in Userform using a variable in a function

    Quote Originally Posted by rorya View Post
    How do you intend to use the function - where will you call it from, for example? Does it actually need to be a function, given that you aren't returning anything?
    you're right, i've made now a change from function to sub, still not updating in real time.
    Attached Files Attached Files

  9. #9
    Forum Contributor
    Join Date
    04-13-2017
    Location
    Buchares
    MS-Off Ver
    2016
    Posts
    117

    Re: Modify in Userform using a variable in a function

    Quote Originally Posted by mikerickson View Post
    Given the name of a userform, this function will return the open userform that has that name.

    Please Login or Register  to view this content.
    If you want to call one of the subs in a userform, you could use CallByName.
    this works nice but i don't understand how / what is the difference between your function and the simple thing as :

    Please Login or Register  to view this content.

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

    Re: Modify in Userform using a variable in a function

    Does the simple thing work?
    That's one difference.

    Its the difference between a variable and it's value

+ 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. [SOLVED] Run-time error '91': Object variable or With block variable not set when closing userform
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 08:59 AM
  2. [SOLVED] Need help to modify Variable strDocPath to a Select files (Dialogwindow)
    By elmnas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-16-2015, 12:52 PM
  3. How to modify a range variable? Should be very simple
    By hadamhiram in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-15-2014, 06:01 PM
  4. Modify Macro for Variable Sheet Name
    By swarchol in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-04-2013, 07:03 PM
  5. [SOLVED] Modify statement to post a zero (0) in the cell when variable = 0 in the equation?
    By Jim15 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-23-2013, 04:19 PM
  6. Excel VBA - Userform as Variable in a Function
    By ericchan1989 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 12-15-2011, 11:31 PM
  7. [SOLVED] Modify range variable passed through Function
    By spyd3r in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 02-14-2006, 07:25 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