+ Reply to Thread
Results 1 to 11 of 11

Increment Variable from User Form Selection

  1. #1
    Registered User
    Join Date
    04-01-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Increment Variable from User Form Selection

    Hi,

    I have a workbook that when opened displays a user form with two buttons. Each button goes to a different worksheet. Basically it gives the option of which worksheet you want to start with. I have a MsgBox that displays with instructions after you make your selection. Then on the sheet you open there is a button to go to the other sheet. I am trying to have that button prompt a MsgBox if the other sheet has not yet been selected. I can get excel to recognize the sheet has been selected once it is toggled to from the other sheet however when I go back to the first sheet it thinks it is the first time. I tried adding code to the form button on_click to increment an occurance variable I have but that does not seem to store whe nthe form is unloaded. Also the occurance variable is declared to the workbook so not within a Sub. Any help?

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

    Re: Increment Variable from User Form Selection

    Did you try declaring the occurance variable as Global?
    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
    04-01-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Increment Variable from User Form Selection

    I believe so. It is declared above any sub procedure in the workbook. Is that what you mean?

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

    Re: Increment Variable from User Form Selection

    It should say:

    Please Login or Register  to view this content.
    in a standard module.

  5. #5
    Registered User
    Join Date
    04-01-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Increment Variable from User Form Selection

    Here is the code, I will try to break it out so you can see the steps....

    Please Login or Register  to view this content.

    So it works perfect except for the fact that the one you select in the form will prompt again when navigated to via the macro. But it will only do it one more time.
    Last edited by jonhfl; 04-01-2010 at 10:56 AM.

  6. #6
    Registered User
    Join Date
    04-01-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Increment Variable from User Form Selection

    I tried changing where I have

    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Same results
    Last edited by jonhfl; 04-01-2010 at 10:57 AM.

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

    Re: Increment Variable from User Form Selection

    Before I can continue to help you, you are going to need to edit your above two posts to include code tags. See the forum rules.

    But: You would want to keep the same variable type: integer, not string.

  8. #8
    Registered User
    Join Date
    04-01-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Increment Variable from User Form Selection

    Sorry I did keep them as Integers. Still does not seem to recognize the increase to the variable from the form.

  9. #9
    Registered User
    Join Date
    04-01-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Increment Variable from User Form Selection

    I got it to work.... I replaced the code with the +1 to call a sub routine to do the increment and it worked.

    Please Login or Register  to view this content.
    I had tried that earlier but I think it was the global that solved it.

    Thank you for the help.
    Last edited by jonhfl; 04-01-2010 at 11:10 AM. Reason: Solved

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

    Re: Increment Variable from User Form Selection

    I think you should remove the message boxes from inside the RunComp_Click() and
    RunReg_Click() procedures. Does that work?

  11. #11
    Registered User
    Join Date
    04-01-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    36

    Re: Increment Variable from User Form Selection

    I guess I could actually just remove everything from teh _Click and just call the Sub? That would clean it up a bit and I think do the same thing. It is working now so I will do a bit of clean up.

+ 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