473,396 Members | 1,797 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,396 developers and data experts.

How to Play Sounds in Access

ADezii
8,834 Expert 8TB
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.
Expand|Select|Wrap|Line Numbers
  1. Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
  2.  
  3. 'The Flags Argument modifies the behavior of sndPlaySound
  4. 'SND_ASYNC - Sound played asynchronously. Code after the Sound function
  5.              'will immediately be executed.
  6.  
  7. 'SND_SYNC - Sound must finish first before further Code is executed
  8. 'SND_LOOP - Can be combined with SND_ASYNC to create a continuous
  9.             'Background Loop
  10.             'iRetValue = sndPlaySound("C:\WAV\MYWAV.WAV", SND_ASYNC + SND_LOOP)
  11. 'The Sound continues playing until the Program executes another sndPlaySound call.
  12.  
  13.  
  14. Public Const SND_ASYNC = &H1
  15. Public Const SND_SYNC = &H0
  16. Public Const SND_LOOP = &H8
2. Make the Call(s) to the API Function from the appropriate Event(s).
Expand|Select|Wrap|Line Numbers
  1. Private Sub Form_AfterUpdate()
  2. On Error GoTo Err_Form_AfterUpdate
  3.  
  4.   Dim iRetValue As Long
  5.   'Record has been successfully Saved
  6.   iRetValue = sndPlaySound("C:\Sounds\TaDA.wav", SND_ASYNC)
  7.  
  8. Exit_AfterUpdate:
  9.   Exit Sub
  10.  
  11. Err_Form_AfterUpdate:
  12.   'some type of Error occurred
  13.   iRetValue = sndPlaySound("C:\Sounds\FogHorn.wav", SND_ASYNC)  MsgBox Err.Description, vbExclamation, "Error in Form_AfterUpdate()"
  14.     Resume Exit_AfterUpdate
  15. 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.
Apr 28 '07 #1
10 26071
I'm interesterd in the enhancements - please share!!!
May 1 '07 #2
ADezii
8,834 Expert 8TB
I'm interesterd in the enhancements - please share!!!
The 2 enhancements that I had previously referred to are:
  1. See if the User's System is capable of playing .WAV files. This can be accomplished via a simply API Function named waveOutGetNumDevs() which will retrieve the number of Waveform-Audio Output Devices in the User's System. If it returns 0, then no capability exists to play .WAVs. The Declaration is listed below and its usage will be in the complete code listing.
    Expand|Select|Wrap|Line Numbers
    1. Declare Function waveOutGetNumDevs Lib "winmm.dll" () As Long
  2. Check and see if the *.WAV actually exists in the specified Path. This can be accomplished via the Dir$() Function. The complete code block is listed below for your reference.
    Expand|Select|Wrap|Line Numbers
    1. Dim iRetValue As Long, strSoundPath As String
    2. strSoundPath = "C:\Sounds\TaDA.wav"
    3.  
    4. If waveOutGetNumDevs() <> 0 Then  'System is capable of playing Sounds
    5.   If Dir$(strSoundPath, vbNormal) <> "" Then      'Valid Path to .wav file
    6.     iRetValue = sndPlaySound(strSoundPath, SND_ASYNC)
    7.   Else
    8.     ''don 't need this - here for demo purposes only. If an empty String
    9.     'is returned by Dir$, do not make an attempt to play the Sound
    10.   End If
    11. End If
May 1 '07 #3
Cool - the training database in my office now plays the theme tune from Team America when anyone presses a button

I thought it'd be funny, no one else does!
May 1 '07 #4
ADezii
8,834 Expert 8TB
Cool - the training database in my office now plays the theme tune from Team America when anyone presses a button

I thought it'd be funny, no one else does!
I share your sense of humor also. Databases can be a little cut-N-dry - I'll try anything, including a little sound, to liven them up!
May 1 '07 #5
They're all trying to figure out whats going on it's hilarious!

I'm on holiday next week - will fix it when I get back haha
May 2 '07 #6
ADezii
8,834 Expert 8TB
They're all trying to figure out whats going on it's hilarious!

I'm on holiday next week - will fix it when I get back haha
I know exactly what you mean. I once created an Inventory System for a Department and once they realized that they could incorporate Sound functionality into the Database, they wanted to use it. On this System, there existed a large number of Lookup Tables to enforce Field Validation. Everytime an incorrect entry was made in a Field, an audible rejection Sound was heard by everyone in the Department. In this case, the use of Sound was not a good thing. It did, however, cut done on Invalid Entries but did nothing for employee morale and didn't make me the most popular person in the area.(LOL).
May 2 '07 #7
well, nice idea...hmm, playing sounds in access? im interested with it but, im not knowledgeable bout it...
Jul 13 '07 #8
ADezii
8,834 Expert 8TB
well, nice idea...hmm, playing sounds in access? im interested with it but, im not knowledgeable bout it...
Just follow the guidelines in Post #1 for the basic approach.
Jul 13 '07 #9
Just follow the guidelines in Post #1 for the basic approach.
Hi! Nice topic you got. Where will i encoded the commands in Post #1?
Sep 24 '07 #10
ADezii
8,834 Expert 8TB
Hi! Nice topic you got. Where will i encoded the commands in Post #1?
In a Standard Code Module.
Sep 24 '07 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Keyser | last post by:
On most my pages, I use Javascript to play a sound. It works fine in Netscape 4.7, Netscape 7.2, Firefox 1.0, IE5 and IE6 using Windows98 as the operating system. However, using WindowsXP as the...
6
by: Andrew Poulos | last post by:
As a follow on to the 'fun' I had with IE I'm now trying to play sounds using an Object tag (no Embed) in MZ. Sadly whenever 'playButton' gets clicked MZ says that "audObj.Play is not a function":...
0
by: MLH | last post by:
Edit, Insert Object & choose Wave Object, the following OLE object thing gets inserted onto the form... Microsoft Sound Recorder Version 5.1 (Build 2600.xpsp2.030422-1633: Service Pack 1)...
22
by: MLH | last post by:
I have some audio help files that play fine from within Access 97 and Access 2.0. Both are running on a Windows XP box. But I do not know what program plays the files. If I click Start, Run and...
6
by: Steph. | last post by:
Hi ! How can I play "standard system sounds" in C# ? ( "standard system sounds" = The kind of sound you hear when you use MessageBox.Show() ) Thanks ! steph.
9
by: ZikO | last post by:
Hi. I'm struggle with playing a wav in Visual Basic. First I wanted to use My.Computer.Audio.Play() method but I realized it's not working if I want to have music in background. I found in...
4
by: elusified | last post by:
Hey guys, i'm currently doing a website that required random background music. But now im facing a problem where how can i modify my current script so that it will auto play the next track instead of...
26
by: Jake Barnes | last post by:
I did a search on the newsgroup comp.lang.javascript. I was searching for "how to play a sound with Javascript". I'm somewhat suprised that the majority of entries are from the 1990s, and there are...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.