Software

Add sounds to your Access form events

Your forms don't have to be silent and boring -- Access lets you play a sound for any form event. Here's a quick look at how you can set up Access to play a sound each time a user opens or closes a form or clicks on a form control.

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:

  1. Open the Form in Design View.
  2. Press Alt + F11.
  3. Go to View | Project Explorer.
  4. Insert | New Module.
  5. 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

  1. Press Alt + Q.
  2. On the form's Property sheet, click in the OnOpen event box on the Event tab.

  1. 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")

  1. Press Alt + Q.


Miss an Access tip?

Check out the Microsoft Access archive and catch up on other Access tips.

Help users increase productivity by automatically signing up for TechRepublic's free Microsoft Office Suite newsletter, featuring Word, Excel, and Access tips, delivered each Wednesday.

Editor's Picks