Playing a sound when a form opens

  • Thread starter Thread starter Mike
  • Start date Start date
M

Mike

When a form opens, I use a call to play a wav file using Media Player with
the following code:

Song = "c:\program files\windows media player\mplayer2.exe
c:\Bully\MyWavFile.wav"
Call Shell(Song, vbMinimizedNoFocus)

This works OK and it keeps Media Player minimized when the file plays. But
is there a way in Access to then close media player altogether so that it
does not stay open (although minimized) in the toolbar? Or, is there a
better way to play the wav file altogether?

Thanks!
Mike
 
For the life of me I can't even imagine why you'd want to do this but:

Add the following declare and const to a Module

Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
Const SND_FILENAME = &H20000

From he place where you are doing a shell do:

Call PlaySound("c:\Bully\MyWavFile.wav", 0, SND_FILENAME)

This will play the sound without loading the media player

Ron W
 
When a form opens, I use a call to play a wav file using Media Player with
the following code:

Song = "c:\program files\windows media player\mplayer2.exe
c:\Bully\MyWavFile.wav"
Call Shell(Song, vbMinimizedNoFocus)

This works OK and it keeps Media Player minimized when the file plays. But
is there a way in Access to then close media player altogether so that it
does not stay open (although minimized) in the toolbar? Or, is there a
better way to play the wav file altogether?

Thanks!
Mike

http://www.mvps.org/access/api/api0011.htm
has code from Dev Ashish to play wav files using API's that works well.


Wayne Gillespie
Gosford NSW Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Sounds 16
Play Sound 4
playing mp3 files with media player control 5
Music won't play 1
Windows Sounds Don't Work 5
Sound output problems 2
Microsoft Media Player 1
c# media player problem 1

Back
Top