How to Play a Song when I open a Form (1 Viewer)

crwc

Registered User.
Local time
Yesterday, 21:01
Joined
Jan 4, 2004
Messages
12
I'm somewhat new to DB's especially when adding all the neat toys.

I want to have a particular song play when ever a form is opened. How would I go about doing this.

I would even consider having a button to activate the song. Again, how would I go about doing this.

TIA
 

crwc

Registered User.
Local time
Yesterday, 21:01
Joined
Jan 4, 2004
Messages
12
Thanks Wayne for the reply.

1) I tried entering 'sounds' in the search and came up with lots! of unrelated info. How do I narrow the search since I'm new to this forum?

2) Is it possible to add a button to play the song on a form? I tried putting in the sound file using both hyperlink and OLE. They gave me the sound when I click on it but when I tab to a new record I lost the link/OLE.

3) How do I set up a form so the form when openned plays only the one song. (the sound should not be part of a record...is this correct in order to 'not' lose it when going to different records)

4) If a button is possible then I would need the code for it...i'm new remember...

5) Or do you have another 'simple' suggestion for this simple task I'm needing help on?

TIA
 

ghudson

Registered User.
Local time
Yesterday, 21:01
Joined
Jun 8, 2002
Messages
6,195
It does not get any easier than this for playing wave files...
Code:
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
HTH
 

crwc

Registered User.
Local time
Yesterday, 21:01
Joined
Jan 4, 2004
Messages
12
Thank you for the code...but forgive me for asking a very dumb question!!!

Where do I put the code? Do I create a button first and paste the code or does it go somewhere else?

Like I said...I'm a beginner!

Thanks again for your very patient help :)
 

WayneRyan

AWF VIP
Local time
Today, 02:01
Joined
Nov 19, 2002
Messages
7,122
crwc,

Just go to the database window, choose Modules (New) and
paste the code in and Save the module with some name. This
is a public module and can be called from anywhere in your
database.

You can make a Command Button on a form and in its
OnClick event, you can put: PlayWaveFile_Cord()

Wayne
 

Users who are viewing this thread

Top Bottom