How to play a sound file when user clicks on an image in a Microsoft Access 2013 Form

Is it possible to get an application you build using Microsoft Access 2013 forms to play a sound (mpeg file) when the user clicks on an image in the form?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

You can play sounds using the sndPlaySound() API:
Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Open in new window

You will need some constants:
Private Const SND_ASYNC As Long       = &H1
Private Const SND_LOOP As Long        = &H8
Private Const SND_MEMORY As Long      = &H4
Private Const SND_NODEFAULT As Long   = &H2
Private Const SND_NOSTOP As Long      = &H10
Private Const SND_SYNC As Long        = &H0

Open in new window

I recommend you use the SND_ASYNC.
Call the function like this:
sndPlaySound "mySound.wav", SND_ASYNC 

Open in new window

To stop it playing call:
sndPlaySound "", SND_ASYNC 

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jeffrey CoachmanMIS LiasonCommented:
Note that this may get annoying to users fairly quickly...
cipriano555Author Commented:
It will show pictures of birds, user clicks on the picture to hear sound, for teaching. Do they have to be wav files, I have .mpg files
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

You can try. Most likely it will not play it. If it does not play (BTW, mpg is a video format, isn't it?) then try the BASS library. It is licenced free for non-commercial applications
You can try using the FollowHyperLink method.  As long as some software is designated as the default when your sound file's file type is opened.  So .docx are defined to open word, .xlsx are defined to open Excel, .accdb are defined to open Access.  The FollowHyperLink method is very flexible.  I haven't tried it with sound files but it is my go to method of opening all other file types since it means that I don't have to know what software is loaded that will read a .pdf file.  I just use FollowHyperLink and as long as .pdf is associated with some application, FollowHyperlink will open it.
cipriano555Author Commented:
I have mp3 sound files.  Thousands of them.  Would be very clumsy to have to convert them to .wav.
Did you try using the FollowHyperlink method?  All you need is to have an audio program associated with mp3 files so Windows knows what app to fire up when you use FollowHyperLink.
cipriano555Author Commented:
I tried the FollowHyperlink method.  I got it to play the sound using VBA in excel, with they huge disadvantage that it  brought up some huge window saying something about XBOX.  I have not got it to work with Access yet.

Private Sub Command0_Click()

Dim fileaudio As String

fileaudio = "C:\Users\cfernandez\Documents\MPEGS\0010.mp3"
Me.FollowHyperlink Address:=fileaudio

End Sub
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.