Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

attaching sound to a command button on a form

Status
Not open for further replies.

Tessadear

Technical User
Mar 7, 2006
26
BB
How can I attach a wav file (sound) to a command button on a form so that when the user click the button the sound plays.
 
Use the following API call to play the WAV file:

Option Compare Database

Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Public Sub x()
Dim retval As Long ' return value of the function

' Play the sound. This function returns when the sound is done.
retval = PlaySound("SystemStart", 0, SND_ALIAS Or SND_SYNC)

' Now loop the .wav file
retval = PlaySound("C:\winnt\media\Windows NT Logon Sound.wav", 0, SND_FILENAME Or SND_ASYNC Or SND_NODEFAULT Or SND_LOOP)

Sleep = 5000 ' wait for 5 seconds while sound loops
retval = PlaySound("", 0, SND_PURGE Or SND_NODEFAULT) ' stop playback
End Sub

Ed Metcalfe.

Please do not feed the trolls.....
 
I used Audacity to record the sound, placed the code into a module and called the code from a command button. My problem is that when I click on the command button the sound plays but stops before the sound is finished. The sound file which is a wav file plays through to the end if I just click on it and play from windows media player.

Is there code I can use to make the sound play to the end using the command button to call the sound. Plays ok by just running the wav file from storage eg. desktop. But when I call the code from the command button the sound ends halfway.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top