preventing command button being clicked twice

Thanks for comments so far.
With staff holiday`s & this being the new year weekend I`m going to have to leave this till end of next week
Best wishes for 2024
Same to you!
 
Timer so button can not be clicked twice 5 seconds

I built in Access VBA the "Fifteen Puzzle" game. Later I added an auto-solve capability.

While auto-solve is auto-playing the game, I found that buttons could be clicked, and cause scrambles to the code.

So I hardened against buttons being pushed while auto-solve is in progress solving the puzzle.

At the Form level I have two flag variables:

Code:
Dim flgAutoPlay As Boolean
Dim flgAutoPlayActive As Boolean

The meaning for flgAutoPlay is if AutoPlay is currently allowed or not.
The meaning for flgAutoPlayActive is if AutoPlay is currently in operation or not.

Times when AutoPlay is not allowed:
1) When the board is cleaned up - The form opens with the game in clean / solved state.
2) When the game has begun being solved by the humanoid
3) When the game has reached the solved state

In the code for each of the buttons:

Code:
Private Sub btn1_Click()

  'Test if AutoPlay is currently operating
  If flgAutoPlayActive = True Then
    Exit Sub
  End If

  Call MovePiece("1")

End Sub

In the AutoPlay button is this code:

Code:
Private Sub btnAutoPlay_Click()

  'Test if AutoPlay is currently operating
  If flgAutoPlayActive = True Then
    Exit Sub
  End If

  Call AutoPlay

End Sub

With the button code checking form variables, that allowed the button to be clicked multiple repeated times safely as the flag variable tells the button code when it needs to exit early.

It was not possible to disable the button as that would blow up the VBA code running within itself. VBA code did not take nicely to being invoked, then attempting to disable the control the code was running in. Maybe that is an indication that VBA does not have self.control?! :cool:

I am thankful,
 
Good evening
I Have an access database in use for about 15 years with minimal probs running our bottled milk business
From the home page a button opens a form where invoices can be created.
As the form opens a query grabs data from the sales tbl & drops it into the preinvoice tbl
then a query marks the records in the sales tbl to show they have been moved.
About 3 times a year we get some duplicate records in the preinvoice table.
Only reason I can think of an impatient user clicks the button twice so the routine runs again grabbing the data before the 1st routine has marked the data.
The routine takes about 5 seconds from click to create invoice form is open
Any sugggestions ?
Timer so button can not be clicked twice 5 seconds
message box saying "wait"
Appreciate your thoughts
TIA
David
I pop a TextBox control on the form that's 0x0.

I set focus to it on MyCommandButton_Click()

and then I can MyCommandButton.enabled = false

and do the rest of the processing I need to do.

e.g.
Code:
Private Sub MyCommandButton_Click()

    Me.txtHidden.SetFocus    '    if we move the focus away, we can disable the active control
    Me.MyCommandButton.Enabled = False

    ...clever stuff

EndProc:
    Me.MyCommandButton.Enabled = True
    Exit Sub

ErrProc:
    '    Err handling
    Resume EndProc

End Sub
 

Users who are viewing this thread

Back
Top Bottom