April 30, 2008
Add sounds to your Access form events
Date: April 29th, 2008
Author: Mary Ann Richardson
Would you like a sound to play each time a user opens or closes a form or clicks on a form control? Access lets you play a sound for any form event. For example, to have a sound play when a form is opened, follow these steps:
- Open the Form in Design View.
- Press Alt + F11.
- Go to View | Project Explorer.
- Insert | New Module.
- Enter this code at the prompt:
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal filename As String, ByVal snd_async As Long) As Long Function Playsound(sWavFile As String) 'Purpose: Plays a sound. 'Argument: the fu11 path and file name. If apisndPlaySound(sWavFile, 1) = 0 Then MsgBox "The Sound Did Not Play!" End If End Function
- Press Alt + Q.
- On the form’s Property sheet, click in the OnOpen event box on the Event tab.
- Click the Build button and then enter the code below at the prompt. (Be sure to use the full pathname to your sound file.)
Playsound ("C:I386Chimes.wav")
- Press Alt + Q.