Sound Button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'd like to make a command button in a form that when pressed plays a sound
associated with the record.

Is this possible?
 
Lori said:
I'd like to make a command button in a form that when pressed plays a sound
associated with the record.


It depends on what kind of sound file you're using. For
simple .wav files, this will do it:
http://www.mvps.org/access/api/api0011.htm

For more complex files, make sure you have installed the
appropriate player program and try using the FollowHyperlink
method.
 
Not sure where in this code to indicate the location of the wav file. I
tried the bottom, where I noticed the chimes sound file had been inserted,
but since I'm not a code writer I'm not quite sure what I'm looking at. Also
don't know what version of access this code is compatible with. I created a
command button, added the code to the on click event.
 
in message:
Not sure where in this code to indicate the location of the wav file. I
tried the bottom, where I noticed the chimes sound file had been inserted,
but since I'm not a code writer I'm not quite sure what I'm looking at. Also
don't know what version of access this code is compatible with. I created a
command button, added the code to the on click event.

Hi Lori,

1. Copy all of that code and place it in a new Standard Module; not in the
form's class module. Save the module with a name of basPlaySounds.
2. Compile the code.
3. On the form in question here is some example code behind a command
button to play a wonderful WAV file by a truly gifted composer named
John Williams:

Private Sub cmdPlaySound_Click()
fPlayStuff ("C:\StarWarsMainTitle.wav")
End Sub

4. Pressing the button in normal view plays the wonderful music.
5. Just provide a suitable file location for your sound file.

Hope that helps,
 
Create a new standard module and Copy/Paste the code in the
article into the module. Compile the module to make sure
it's correct.

The code for your command button would be similar to the
lines in the faTest function or even just one line like:

fPlayStuff "C:\Program Files\Windows NT\Pinball\SOUND17.WAV"
 
Thank you. I can get the sound to play now. But I want to assign a new
sound per record that is displayed on the form. Each record will have its
own unique picture and sound. The picture part is easy, but how can I make
the command look to the individual record and plug in the appropriate sound
file?

Marshall Barton said:
Create a new standard module and Copy/Paste the code in the
article into the module. Compile the module to make sure
it's correct.

The code for your command button would be similar to the
lines in the faTest function or even just one line like:

fPlayStuff "C:\Program Files\Windows NT\Pinball\SOUND17.WAV"
--
Marsh
MVP [MS Access]



Lori said:
Not sure where in this code to indicate the location of the wav file. I
tried the bottom, where I noticed the chimes sound file had been inserted,
but since I'm not a code writer I'm not quite sure what I'm looking at. Also
don't know what version of access this code is compatible with. I created a
command button, added the code to the on click event.
 
in message:
Thank you. I can get the sound to play now. But I want to assign a new
sound per record that is displayed on the form. Each record will have its
own unique picture and sound. The picture part is easy, but how can I make
the command look to the individual record and plug in the appropriate sound
file?

Let's assume you have a field in the table called PathToSoundFile and you
have a corresponding control on the form bound to that field called
txtPathToSoundFile. The code behind the command button would now
look like this:

' *******Code Start*********
Private Sub cmdPlaySound_Click()
On Error GoTo ErrorPoint

Dim strPath As String

If Len(Nz(Me.txtPathToSoundFile, "")) = 0 Then
' No sound file path present so just ignore
' You could also play a "No Sound" file
' or a Windows one if desired
Else
' Sound file path present
strPath = Me.txtPathToSoundFile
fPlayStuff (strPath)
End If

ExitPoint:
Exit Sub

ErrorPoint:
MsgBox "The following error has occurred:" _
& vbNewLine & "Error Number: " & Err.Number _
& vbNewLine & "Error Description: " & Err.Description _
, vbExclamation, "Unexpected Error"
Resume ExitPoint

End Sub
' *******Code End*********

This will work with forms in Single or Continuous layout.
You optionally could save the record first if you desire as well.

Hope that helps,
 
Thanks to your Sound Button discussion including all the scripting I now can
play more tham one piece of WAV-music under one button. Magic !
Now I'd like students to answer questions by clicking radiobuttons while a
piece of music is playing. There I have a problem: When a wavefile is playing
there is no other (mouse)activity possible. Can you help me solve this
problem ?
 
Hello Jeff,

Thanks for supplying that button code, it worked for me too. I'm not a coder
in any sense, but after a little trial and error, (I don't know how to
compile a modul...) I somehow got it to work for me. It has been a while
since this thread was started, and I was wondering if you had found a way for
the mouse to work while the Wav was playing?

regards

Eric
 
Hi,
I get an error msg: Expect procedure, not variable.. What's wrong?

Private Sub cmdPlaySounds_Click()
fPlayStuff "Honk.wav"
End Sub

Thank you,
Karl
 
Back
Top