Run a .wav file when a button is clicked

Ease of Use


Version tested with


Submitted by:



This shows you hot to set up a button in Access so that when you click on it, it will open Windows Media Player and play a wav file. 




instructions for use


Option Compare Database Option Explicit Declare Function PlaySound Lib "winmm.dll" _ Alias "PlaySoundA" ( _ ByVal lpszName As String, _ ByVal hModule As Long, _ ByVal dwFlags As Long) As Long Function PlayWav() 'Change the file path of the wav file as needed. Call PlaySound("C:\WINDOWS\Media\chimes.wav", 0&, &H1 Or &H20000) End Function

How to use:

  1. First open the VBE and Insert a Module. Then paste in this code.
  2. Close the VBE and go to Access.
  3. Click on Macros and then New.
  4. For the Action dropdown select RunCode. For the Function Name field type in PlayWav (). Then close and save the macro.
  5. Go to your form and add a Command Button. In the Command Button Wizard select Miscellaneous and Run Macro then press Next. Then select the macro from the list and press Next. Finish the rest of the wizard.
  6. The Command Button should now play the wav file when clicked.
  7. An example attachment has also been posted.

Test the code:

  1. View the Form in the Form view and click on the button. You should hear whatever wav you placed in the macro.

Sample File: 11.5KB 

Approved by mdmackillop

This entry has been viewed 127 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express