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
 
Back
Top