Command Button - 1 Click Runs Code 3 Times

M

Michael E. Hill

I have a Command Button on a form that should run a Public VBA Subroutine
only once, unfortunately the subroutine runs three times for every one click
of the button. Setting AutoRepeat to YES or NO makes no difference. This
occurs on two different computers running Access 2000 and a third computer
running Access 2002.

Here's a simple example in a new, otherwise empty, database.

1 form, named frmTestForm
frmTestForm contains 1 Command Button, named cmdTest
cmdTest On Click Event set to =[TestProcedure]

The entire contents of the VBA code on Form_frmTestForm (or the entire DB
for that matter) are:

Option Compare Database

Public Sub TestProcedure()
MsgBox ("Running Test Procedure")
End Sub

Clicking cmdTest on frmTestForm should obviously produce a single Message
Box, but it produces it three times!

Anyone know why? Or even better, anyone know how to fix this?

Thanks,

Michael
 
G

Graham Mandeno

Hi Michael

Change your Sub declaration to Function:
Public Function TestProcedure()
(it doesn't need to return any value)

And change the OnClick property to a function call:
=TestProcedure()

If the function is not being called from outside this form then it can be
declared Private.

I haven't seen this particular flavour of the problem before, but it seems
to be related to the following KB article:
http://support.microsoft.com/?kbid=207860
 

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