• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 615
  • Last Modified:

How do I launch a .wav file with windows media player minimized to play for 10 sec when in Microsoft Access when a form loads?

How do I launch a .wav file with windows media player minimized to play for 10 sec when in Microsoft Access when a form loads?
1 Solution
record 10 seconds wav file
in starter module/form open another small form first, open player, set property minimized, specify file to play and start playing.
with the next statement in starter module open your form which takes 10 seconds to get loaded, when it is loaded you might call function from the form, which started started media player to close it and then close that form too.

You could also use MCI32.OCX instead of windows media player.
Create a module with this
Option Compare Database
Declare Function MessageBeep Lib "user32.dll" (ByVal wType As Long) As Long
Public MySound() As Long ' return value
Public Const MB_ICONASTERISK = &H40
'Play the SystemAsterisk sound.
'Play the SystemExclamation sound.
Public Const MB_ICONHAND = &H10
'Play the SystemHand sound.
Public Const MB_ICONQUESTION = &H20
'Play the SystemQuestion sound.
Public Const MB_OK = &H0
'Play the SystemDefault sound.
'Play a regular beep
Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal LpszSoundName As String, ByVal hMod As Long, ByVal uFlags As Long) As Long
Option Explicit

Public Function PlayWavFile(strPath As String)
    Dim snd_async As Long
    Call PlaySound(strPath, 0, snd_async)
End Function

On open or whatever call this code:

Call PlayWavFile("C:\your wav file")
How long is your wave file now? If u cut it down to 10 seconds (u can still use the good old windows recorder for that), u can simply call this api

Private Declare Function sndPlaySoundA Lib "WINMM.DLL" (ByVal lpszSoundName As String, ByVal ValueFlags As Long) As Long

Global Const SND_ASYNC = &H1
Global Const SND_NODEFAULT = &H2

Public Sub PlayWaveFile(ByVal sFile As String)
  Dim lRet As Long
  lRet = sndPlaySoundA(sFile, SND_ASYNC Or SND_NODEFAULT)
End Sub

Add the above code to a module and call the function PlayWaveFile

PlayWaveFile "c:\fred.wav"

note its asynchronous so function will return even though music still playing in the background
Easily Design & Build Your Next Website

Squarespace’s all-in-one platform gives you everything you need to express yourself creatively online, whether it is with a domain, website, or online store. Get started with your free trial today, and when ready, take 10% off your first purchase with offer code 'EXPERTS'.

Sorry wiswalld, your post wasnt there when I started typing
tkschultz1207Author Commented:
I don't have time to record just ten seconds, is there a way in code I can say stop executing that file after say the timer is up on the form?
Ok, on form_load u play the sound, obviously and set the form's timer to kick in after 10 seconds

then to stop playing the music, u add the code to in the form_timer event

private sub form_timer
end sub

and the code posted earlier to play a wave file? add this in

Public Sub StopWaveFile()
  Dim lRet As Long
  lRet = sndPlaySoundA(vbNullString, SND_ASYNC)
End Sub

>> I don't have time to record just ten seconds

sound recorder does it for you, u simply move the timer to 10secs then use the menu command to trim the rest then save as
its as simple as that
less than 2 mins work
ok, I see you accepted whilst I was answering your other question
I guess you must of figured it out then
tkschultz1207, just out of curiosity, would you mind telling us how u went about solving the problem of 10 seconds play only?
tkschultz1207Author Commented:
Sorry, I accepted the answer before you answered about the 10 seconds. I ended up not cutting the .wav file to 10 seconds and just played the entire .wav on close of the form which ended up being fine, since my presentation was due at 11am Texas time. Thanks for your help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now