+ Reply to Thread
Results 1 to 3 of 3

Pass Value/text from User Form to Macro

  1. #1
    Registered User
    Join Date
    05-24-2011
    Location
    Stockholm
    MS-Off Ver
    Excel 2007
    Posts
    2

    Pass Value/text from User Form to Macro

    Hello All!
    I have tried this solution before and it worked, but I cannot repeat the same task. I have a Database where I am supposed to look up information, and if not found add as a new row with new information. I use User forms and Macros, but the values seem not to correspond. I am new at this, so please explain clearly. The below code gives the right value in User Form, but gives the value BuggNr=0 for the Macro code. The reason why both macro and user form is why I am planning on doing several more tasks
    PLS ADV
    Thanks in before
    /Thomas

    Please Login or Register  to view this content.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Pass Value/text from User Form to Macro

    This has to do with the scope of the variable. I'd suggest Googling "Variable Scope" to find a good article that will help you understand all about variable scope. In a nutshell, the buggNR variable is exclusive to your CB_Hitta_Click() macro. Once that macro ends, the variable is nothing. The best way to get around this in your case should be to pass the variable as an argument in the HittaBug method.

    Something like this:

    Please Login or Register  to view this content.
    This also brings up the importance of declaring all variables with a dim statement.
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    05-24-2011
    Location
    Stockholm
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Pass Value/text from User Form to Macro

    Excellent Dave! Thanks a lot. Will look up that article about variable scope

+ 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