Most Access Users fail to realize that they can significantly enhance their applications by introducing various sounds (*.WAVs) in response to specific events. The only intrinsic sound that Access can generate is the DoCmd.Beep which is hardly worth the time to mention. You can incorporate sound functionality into your Access applications via a single call to a relatively simple API Function. A couple of arguments to the Function dictate where the sound file (*.WAVs) is located, and how the sound is played. The code below will play the all-too-familiar
TaDa.wav once a Record has been successfully saved, and
FogHorn.wav if an Error is generated in the Update operation. Carefully follow the steps below which are listed in sequence.
1. Declare the API Function within a Standard Code Module along with its Flags Arguments.
- Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
-
-
'The Flags Argument modifies the behavior of sndPlaySound
-
'SND_ASYNC - Sound played asynchronously. Code after the Sound function
-
'will immediately be executed.
-
-
'SND_SYNC - Sound must finish first before further Code is executed
-
'SND_LOOP - Can be combined with SND_ASYNC to create a continuous
-
'Background Loop
-
'iRetValue = sndPlaySound("C:\WAV\MYWAV.WAV", SND_ASYNC + SND_LOOP)
-
'The Sound continues playing until the Program executes another sndPlaySound call.
-
-
-
Public Const SND_ASYNC = &H1
-
Public Const SND_SYNC = &H0
-
Public Const SND_LOOP = &H8
2. Make the Call(s) to the API Function from the appropriate Event(s).
- Private Sub Form_AfterUpdate()
-
On Error GoTo Err_Form_AfterUpdate
-
-
Dim iRetValue As Long
-
'Record has been successfully Saved
-
iRetValue = sndPlaySound("C:\Sounds\TaDA.wav", SND_ASYNC)
-
-
Exit_AfterUpdate:
-
Exit Sub
-
-
Err_Form_AfterUpdate:
-
'some type of Error occurred
-
iRetValue = sndPlaySound("C:\Sounds\FogHorn.wav", SND_ASYNC) MsgBox Err.Description, vbExclamation, "Error in Form_AfterUpdate()"
-
Resume Exit_AfterUpdate
-
End Sub
3. The above code can further be improved by first checking to see if the User's System supports the playing of sounds, and if the requested file actually exists. If anyone is interested in viewing either one of these enhancements, please let me know.