Click event to run only once

  • Thread starter Thread starter gavmer
  • Start date Start date
G

gavmer

HI again,

I apologise for my persistence but im really stuck!! Can someone sho
me how to apply so that my click event runs only once??

Thanks in advance!
 
One way to do it is to use a Static variable, so it
retains its value between calls. If you use a Boolean,
you can use it to flag when the sub has been run
previously, and if so to abort processing the code; e.g:

Sub Button1_Click()

Static Pressed As Boolean

If Not(Pressed) Then

' Insert your code here

End If

Pressed = True

End Sub

First time this is run, Pressed starts out false so your
code runs. But then Pressed is set to True and the value
is retained between calls - so next time it will fail the
IF statement and the code will be bypassed.

K Dales
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top