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!

Play an audio "wav" file

Status
Not open for further replies.

csegal

Technical User
Jun 12, 2001
38
US
I would like to add an audio sound file to play when a particular button on a form is pressed.
Is there some code to add to the button that already has code to open a particular form?
If so...
Where do i place the "sound code" ?
Please be descriptive as I am not very programmer savy.
I am using Access 97...

Thanks...
csegal@arrowair.com

FancyPrairie (Programmer)gave this to me but it is all greek to me.

Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Function PlaySound(FileName As String)

Dim MyReturn As Long

MyReturn = sndPlaySound(FileName, 1)
If (MyReturn <> 1) Then GoTo ErrHandler

'********************
'* Exit Procedure *
'********************

ExitProcedure:

Exit Function

'****************************
'* Error Recovery Section *
'****************************

ErrHandler:

Msgbox &quot;Error from sndPlaySound&quot; & vbCrLf & &quot;Value is &quot; & MyReturn, vbExclamation

GoTo ExitProcedure

End Function
 
Open a New Module and insert the code above. Then save the module as basPlaySound (or whatever name you want).

Then open your form in design view and on the OnClick event of the button, insert this:
=PlaySound (&quot;WaveFileName&quot;)
where &quot;WaveFileName&quot; is the name (and path) of your .wav file.

That should do it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top