Simple Question, I hope!

spectrolab

Registered User.
Local time
Today, 09:54
Joined
Feb 9, 2005
Messages
119
Hi Guys,

I have a form that has a few buttons on it, fairly basic. One of the buttons performs an action, and when the form is open, I might press it up to 20 times with different values in the form. Basically, the button appends records to a table based on values I put in text boxes.

What I am trying to do is to have something that, when the form opens, sets a value for a parameter at say =1, then is uses that value in the button code. At the end of the button code it adds 1 to this parameter and retains the new value (in this case 2) until the button is pressed again. When the form closes (or re-opens) I need to set the value back to one.

I am sure that it is fairly easy to do, but I am having a mental block at the moment.
 
Dim a global variable in the class module of your form before any SubRoutines:
Dim MyVariable As Integer
...then in the OnLoad event of the form put:
MyVariable = 1
...and in the ControlSource of your TextBox put:
=MyVariable
...and in the ClickEvent of your CommandButton put:
MyVariable = MyVariable + 1
 
Thanks RG, works like a charm.
 

Users who are viewing this thread

Back
Top Bottom