Access 2002 Command button Click event reentrant in nature?

  • Thread starter Kunjal Karamshi
  • Start date
K

Kunjal Karamshi

I seem to be having a problem with Access Xp in that if a
user clicks a button and clicks it again after a few
seconds, the click event fires again even though the code
has not yet completed executing the first time.

To illustrate this I have a piece of code as shown below:

Private Sub Button1_Click()

Dim i As Long

For i = 1 To 1000000
DoEvents
Next i

End Sub

If I run this code, I can click the button and click it
again a few seconds later and the event will fire again. I
was even able to place the form in design mode while the
code was still running!

Is this behaviour by design or is it a bug? On my side
this has lead to subtle errors whenever a user clicks on a
button twice. Is there any way of turning this behaviour
off?

Kunjal
 
A

Albert

Hi, This behavior is normal, not bug. To prevent user from second click, I
always disable this command button after start of routine and enable it
again wherever exit procedure. Remark : before you can disable the required
command button (or any controls), you have to set focus to any other
controls. Otherwise, error occurs.

Hope this may help.
 
T

TC

This is the message-diven nature of Windows. The doevents has relinquished
control for further message processing. That is how & why the second click
got in. If you omit the doevents, the second click will not be seen until
the first has finished running.

In addition, Access VBA is single threaded. So even though the doevents has
let the second click get in, I think you will find that this does not
constitute a seperate thread, with seperate state. The second click will
disrupt the first click's state.

HTH,
TC
 

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

Top