TechGuise
asked on
Command button Click Event running twice on Double Click
I have a small app that runs on a tablet which will allow small children to answer a few questions (psychological questions).
We have a command button that when clicked, it will play an audio file that is attached to that question number.
All is working well except that if the child touches button twice (in essence double clicks), then it runs the "CLICK" event twice.
I've tried lots of suggestions found, but none work. The last thing I tried (see code), was to send focus to another benign button, set ENABLE to false at beginning of code, then reverse at end.
It still plays twice.
Any help would be greatly appreciated.
We have a command button that when clicked, it will play an audio file that is attached to that question number.
All is working well except that if the child touches button twice (in essence double clicks), then it runs the "CLICK" event twice.
I've tried lots of suggestions found, but none work. The last thing I tried (see code), was to send focus to another benign button, set ENABLE to false at beginning of code, then reverse at end.
It still plays twice.
Any help would be greatly appreciated.
Private Sub HearAgain_Click()
On Error GoTo ButtonError
Me.cmdBeep.SetFocus
Me.HearAgain.Enabled = False
Dim stID As String
stID = Me.ID.Value
Me.Repaint
sndPlaySound "C:\ChildSurvey\Audio\Q" & stID & ".wav", SND_ASYNC
Me.HearAgain.Enabled = True
Me.HearAgain.SetFocus
Exit Sub
ButtonError:
DoCmd.Echo True
DoCmd.SetWarnings True
Dim stErrMSG As String
stErrMSG = MsgBox(Err.Description)
End Sub
You are part way there, but you also need to wait for the sound to finish before enabling the button again. So you need to use SND_SYNC instead of SND_ASYNC. See here for more info - https://msdn.microsoft.com/en-us/library/windows/desktop/dd798676(v=vs.85).aspx
ASKER
Was very hopeful.... made sense. But still plays twice.
Is there something else I need to do to make the SND_SYNC take effect?
Is there something else I need to do to make the SND_SYNC take effect?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Realized I didn't post that I had already set the constant value. (exactly as shown in that link)
If no one else has anything, might just go with the OPTION button.
Jeff - I kind of agree, the thing playing twice doesn't seem like that big of a deal... but unfortunately my opinion doesn't have much weight regarding this. I have some answer buttons (YES & NO) being hidden while the sound is playing, so it is a little distracting that they appear and disappear each cycle of sound play.
Anyway, I'll give this another day to see if anyone has a guess as to what I've done wrong & then close the question. Thank you both for responses.
If no one else has anything, might just go with the OPTION button.
Jeff - I kind of agree, the thing playing twice doesn't seem like that big of a deal... but unfortunately my opinion doesn't have much weight regarding this. I have some answer buttons (YES & NO) being hidden while the sound is playing, so it is a little distracting that they appear and disappear each cycle of sound play.
Anyway, I'll give this another day to see if anyone has a guess as to what I've done wrong & then close the question. Thank you both for responses.
OK
Thanks for the feedback.
I was just curious
Thanks for the feedback.
I was just curious
ASKER
BTW, I didn't see the database attachment until a few minutes ago. Thanks!
The "API_PlaySound" method seems to act slightly different than the "sndPlaySound "..... testing now to see if it's a "good different"
The "API_PlaySound" method seems to act slightly different than the "sndPlaySound "..... testing now to see if it's a "good different"
ASKER
OK, so using the API_PlaySound instead of sndPlaySound, it starts playing the audio file over immediately (instead of letting it play completely and then playing again.... for each time the button was pressed). For this particular app, API_PlaySound is a much better solution.
My challenge is now... my YES/NO buttons don't stay hidden until the audio finishes.. I changed the code Jeff gave me in the sample database to use the SND_SYNC instead of SND_ASYNC, but still no.
Some of these audio questions are much longer than others, and there is a fear the child will answer before the question is finished if the buttons are available.
This app has been kind of depressing. I keep having to hear a nice lady ask questions like "has anyone ever touched you...", is anyone who lives in your home in jail, or been killed...". Not the most uplifting project I've had.
Thanks again for your help.
My challenge is now... my YES/NO buttons don't stay hidden until the audio finishes.. I changed the code Jeff gave me in the sample database to use the SND_SYNC instead of SND_ASYNC, but still no.
Some of these audio questions are much longer than others, and there is a fear the child will answer before the question is finished if the buttons are available.
This app has been kind of depressing. I keep having to hear a nice lady ask questions like "has anyone ever touched you...", is anyone who lives in your home in jail, or been killed...". Not the most uplifting project I've had.
Thanks again for your help.
'<<< Module1 >>>
Option Compare Database
Option Explicit
Const SND_SYNC = (1)
Const SND_NODEFAULT = (2)
Declare Function sndplaysound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Function API_PlaySound(pWavFile As String)
Dim LResult As Long
'Make a Windows API call to play a wav file
LResult = sndplaysound(pWavFile, SND_NODEFAULT + SND_SYNC)
End Function
'<<< Button on form >>>
Private Sub HearAgain_Click()
On Error GoTo ButtonError
Call HideBtns_Click
Dim stID As String
stID = Me.ID.Value
Me.Repaint
API_PlaySound "C:\ChildSurvey\Audio\Q" & stID & ".wav"
Call UnhideBtns_Click
Exit Sub
ButtonError:
DoCmd.Echo True
DoCmd.SetWarnings True
Dim stErrMSG As String
stErrMSG = MsgBox(Err.Description)
End Sub
ASKER
Double play is more tolerable with the API_PlaySound since it starts over immediately. Going with that.
Thanks for the help gentlemen.
Thanks for the help gentlemen.