How to play a wav file from VB

Please provide code that will have a Command button press play a Wav file.
It would be wonderful if a player didn't appear. I'd like this to be completely automatic.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can use the PlaySound API..

  Private Const SND_ALIAS& = &H10000
  'Playsound returns immediately
  'Do not use SND_SYNC
  Private Const SND_ASYNC& = &H1
  'The name of a wave file.
  'Do not use with SND_RESOURCE or SND_ALIAS
  Private Const SND_FILENAME& = &H20000
  'Unless used, the default beep will
  'play if the specified resource is missing
  Private Const SND_NODEFAULT& = &H2
  'Fail the call & do not wait for
  'a sound device if it is otherwise unavailable
  Private Const SND_NOWAIT& = &H2000
  'Use a resource file as the source.
  'Do not use with SND_ALIAS or SND_FILENAME
  Private Const SND_RESOURCE& = &H40004
  'Playsound will not return until the
  'specified sound has played. Do not
  'use with SND_ASYNC
  Private Const SND_SYNC& = &H0

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

You use it with code like..

a6106aAuthor Commented:
vbmaster: Great. Works fine. Just need to know how to (from VB) stop the wav file from playing. As is, looks like I have to wait for it to stop itself.??
a6106aAuthor Commented:
VBMASTER: also , do you know if its possible to play an MP3 file from VB?
If so how please.
You can use the "Microsoft Activemovie Control" for playing MP3's. Check your Project -> Components, if you don't have it I guess you can download it somwhere on Microsoft's homepage..
Use the following code to stop the wav file from playing..

  Call PlaySound("", 0, 0)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.