Tedsmith's code should have worked fine. You might try the alternate declaration (remember that all API decs are case sensitive): [tt]
Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long [/tt]
The last parameter, dwFlags, is the one you might be interested in. Here are the possible values:
[tt]
[tab]SND_ALIAS = &H10000[/tt]
lpszName is a string identifying the name of the system event sound to play.
[tt]
[tab]SND_ALIAS_ID = &H110000[/tt]
lpszName is a string identifying the name of the predefined sound identifier to play.
[tt]
[tab]SND_APPLICATION = &H80[/tt]
lpszName is a string identifying the application-specific event association sound to play.
[tt]
[tab]SND_ASYNC = &H1[/tt]
Play the sound asynchronously -- return immediately after beginning to play the sound and have it play in the background.
[tt]
[tab]SND_FILENAME = &H20000[/tt]
lpszName is a string identifying the filename of the .wav file to play.
[tt]
[tab]SND_LOOP = &H8[/tt]
Continue looping the sound until this function is called again ordering the looped playback to stop. SND_ASYNC must also be specified.
[tt]
[tab]SND_MEMORY = &H4[/tt]
lpszName is a numeric pointer refering to the memory address of the image of the waveform sound loaded into RAM.
[tt]
[tab]SND_NODEFAULT = &H2[/tt]
If the specified sound cannot be found, terminate the function with failure instead of playing the SystemDefault sound. If this flag is not specified, the SystemDefault sound will play if the specified sound cannot be located and the function will return with success.
[tt]
[tab]SND_NOSTOP = &H10[/tt]
If a sound is already playing, do not prematurely stop that sound from playing and instead return with failure. If this flag is not specified, the playing sound will be terminated and the sound specified by the function will play instead.
[tt]
[tab]SND_NOWAIT = &H2000[/tt]
If a sound is already playing, do not wait for the currently playing sound to stop and instead return with failure.
[tt]
[tab]SND_PURGE = &H40[/tt]
Stop playback of any waveform sound. lpszName must be an empty string.
[tt]
[tab]SND_RESOURCE = &H4004[/tt]
lpszName is the numeric resource identifier of the sound stored in an application. hModule must be specified as that application's module handle.
[tt]
[tab]SND_SYNC = &H0[/tt]
Play the sound synchronously -- do not return until the sound has finished playing.
Try this:
[tt]
Dim retval As Long 'this will be non-zero if successful
retval = PlaySound("C:\Windows\MySound.wav", 0, SND_FILENAME Or SND_ASYNC Or SND_NODEFAULT Or SND_LOOP)
If retval = 0 Then
MsgBox "Couldn't play that sound!, vbCritical, "Oops!"
End If
[/tt]
Hopefully, you have a file in your Windows folder called "MySound.wav". You will need to include the following line in the Form Unload event to prevent the memory leakage Tedsmith mentioned:
[tt]
retval = PlaySound("", 0, SND_PURGE Or SND_NODEFAULT)
[/tt]
Alt255@Vorpalcom.Intranets.com