PDA

View Full Version : Solved: Can I save parameters between UserForm shows?



EdNerd
09-25-2012, 10:18 AM
I'm using some code to detect when a calendar reminder pops up. I want to use this to Show a UserForm.

I'd like to generate a random number and use that to pull in a specific block of text. But ideally I'd like to only generate the number once, and then I can increment it around my loop on successive Shows.

But that would require that I can somehow keep track of (a) my original number, and (b) how many times I've been around the loop so far. Everything with the UserForm gets destroyed when I close it. Is there any way to save or write these parameters to someplace the userForm can grab it on the next Show?

Ed

BrianMH
09-26-2012, 06:17 AM
Add a module and at the top outside of any sub/function declare a variable for example:


Option explicit
Dim iNum as integer

sub asdf
'code of a sub
end sub


Then whenever you show your userform have it grab the value of the variable and increment it by 1.


iNum = iNum + 1

EdNerd
09-26-2012, 09:33 AM
I've got the Sub in ThisOutlookSession, and I generally don't close my OL (unless my computer locks up!!). So that variable will stay alive after the Sub is completed?

Ed

BrianMH
09-26-2012, 11:47 AM
Yes as long as it is declared outside of the sub it will remain as long as the application is open.

EdNerd
09-26-2012, 12:37 PM
That's my answer, then! Thank you!!!
:bow: :thumb