+ Reply to Thread
Results 1 to 2 of 2

Update record - how to pass variable from one userform module to another

  1. #1
    Forum Contributor
    Join Date
    02-16-2012
    Location
    London, England
    MS-Off Ver
    Excel mac 2011
    Posts
    238

    Update record - how to pass variable from one userform module to another

    Hi there,

    I have a userform that finds a record from an excel spreadsheet. But now I want to be able to reference that and add comments to it at a later date. How can I assign the record address (from a part number) so that the userform will edit that line? I could use a global variable, though I am loath to as to me global variables can be a little sloppy. It is likely that this spreadsheet/userform/macro will grow. I C you just declare a variable when the function is called and then the function returns a value.

    How is this done in VBA?

    Kind regards
    Rob

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Update record - how to pass variable from one userform module to another

    I do this very thing all the time in Userforms. I declare a PUBLIC long variable called CurrRow and store the row number that was is currently being used in the form. I use that value to update my DB sheets in when textboxes are changed on my form and an "UPDATE" button is selected. It is far from sloppy, it is quite surgical.

    When the UPDATE is done and values are written back to the sheet, the form is cleared and the CurrRow value is cleared as well.

    Perhaps by sloppy you meant "a mistake on how the variable is used can lead to errors on the database". Yes, but that of course is true of all variables and of all forms that write to worksheet dbs, you have to get it right.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

+ 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. Pass Variable From UserForm to Module
    By BLLMRC in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-24-2013, 12:41 PM
  2. [SOLVED] Pass date variable to another procedure/module
    By maacmaac in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-20-2013, 10:16 PM
  3. [SOLVED] Pass variables from userform to module
    By Bishonen in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2012, 07:54 AM
  4. Pass variable between subs within module
    By oOarthurOo in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-01-2010, 04:58 PM
  5. [SOLVED] Pass variable from module to userform and back
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-20-2006, 11:50 AM

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