Sound in a Form

sondriven

Registered User.
Local time
Today, 05:41
Joined
Jun 13, 2002
Messages
158
I posted this in the General Forum. Dont know if that was the right spot so Im trying here. Please dont offend.



I want to add a sound for when someone quits the database.


Sound File name - ByeBye
Ive tried adding this to the Event of my Quit Application button.

Me!ByeBye.Action = acOLEActivate

I inserted the sound file into the form.

But it does nothing. Could I bother someone for some help with this?

Thanks
 
I tried a lot on that page and can get none of it to work. My database isnt liking the "Const" Property.

Any suggestions?
 
Multi posting the same question is frowned upon. ;)

I have successfully used Dev's code that Mile-O-Phile directed you too. I also have discovered a working solution that does not require as much code.

For those in need, here is the response I posted in your first thread...

Copy this into a module...

Option Compare Database
Option Explicit

'PlayWaveFile
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal filename As String, ByVal snd_async As Long) As Long

Public Function PlayWaveFile(sWavFile As String)
If apisndPlaySound(sWavFile, 1) = 0 Then
'MsgBox "The Sound Did Not Play!"
End If
End Function

Public Sub PlayWaveFile_Cord()
Call PlayWaveFile("C:\Windows\Media\chord.wav")
End Sub

My example will play the standard 'chord' wave file. To call it from another event in your db, just use this...

Call PlayWaveFile_Cord

HTH
 
ghudson,

Your example code and call are great. I tried it on the splash screen I created to open a program.

I believe that I pasted all your code in correctly to a module I named Sound2. My call statement is on the OnOpen event of the splash form.

Stepping through, it does not hit the msgbox statement (I uncommented it) but I get a sound (the you screwed up sound, but it could be a chord).

So I changed the sound to \windows\clap.wav and got a bell. But the clap does work.

I am running on Win98 and Access97.

Do you have any suggestions?
 
Sorrells,

Can you post your Access 97 db (just the splash form and the Sound2 module) and I will take a look at it.
 
ghudson,

Here it is. You will need to add a graphic file to the OnOpen Event and the gblGraphicsPath will most likely not make sense but the only intent is to display an image. I call the sound module here also.

I appreciate your help!
 

Attachments

It worked for me. Are you sure the wav file path and name is correct for your PC? I modified the Sub to test that the file can be found...

Code:
Public Sub PlayWaveFile_Cord()
    
    Dim sWav As String
    sWav = "C:\Windows\media\ding.wav"
    
    If Dir(sWav) = "" Then
        Beep
        MsgBox "Wave file can NOT be found!"
        Exit Sub
    Else
        'MsgBox "Wave file found, enjoy!"
    End If
    
    Call PlayWaveFile(sWav)
    
End Sub
HTH
 
ghudson,

Thanks for your response! I took the application to the office where my client is and loaded the changes there. It worked fine.

On return to home, I found that for this PC I was missing a sub-directory in my path. Once corrected it worked fine.

Very cool and neat. U R 2 Cool!
 

Users who are viewing this thread

Back
Top Bottom