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
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.
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
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
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?!
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
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