preventing command button being clicked twice (1 Viewer)

Pat Hartman

Super Moderator
Staff member
Local time
Today, 03:06
Joined
Feb 19, 2002
Messages
43,275
Please also respond to #18
 

GPGeorge

Grover Park George
Local time
Today, 00:06
Joined
Nov 25, 2004
Messages
1,867
People ! ;)
A user who is prone to being impatient if he is under pressure.
Hence my initial thought, the simple solution was to prevent multiple clicks of the button
Coding around the actions of a single user is an endless series of ploys and counter ploys.

Why not investigate the suggestions of experienced developers who've offered alternatives in this discussion.
 

Isaac

Lifelong Learner
Local time
Today, 00:06
Joined
Mar 14, 2017
Messages
8,777
Ebs comment made me remember another piece of advice. Not only do I recommend disabling a button while slower procedures run, but remember to enable it (of course) when the procedure finishes - and remember to have an error handler that enables the button too.
anything you do in code that you would hate to have it 'stuck' that way, remember to have an error handler and un-do that change.

a few common examples are:

application.displayalerts=false (excel)
application.screenupdating=false (excel)
application.enableevents=false (excel & access)
setwarnings (access)
disabled buttons, etc. etc.
 
Last edited:

upnorth

New member
Local time
Today, 08:06
Joined
Feb 12, 2015
Messages
9
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
 

Isaac

Lifelong Learner
Local time
Today, 00:06
Joined
Mar 14, 2017
Messages
8,777
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!
 

mdlueck

Sr. Application Developer
Local time
Today, 03:06
Joined
Jun 23, 2011
Messages
2,631
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,
 

whomademe

New member
Local time
Today, 00:06
Joined
Jan 4, 2018
Messages
3
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

Top Bottom