473,612 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Play Sounds in Access

ADezii
8,834 Recognized Expert Expert
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 26152
motherfunker
7 New Member
I'm interesterd in the enhancements - please share!!!
May 1 '07 #2
ADezii
8,834 Recognized Expert Expert
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 waveOutGetNumDe vs() 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
motherfunker
7 New Member
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 Recognized Expert Expert
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
motherfunker
7 New Member
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 Recognized Expert Expert
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
maricar
5 New Member
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 Recognized Expert Expert
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
rhentaberdo
1 New Member
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

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

Similar topics

2
2181
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 operating system, the entire Netscape 7.2 browser and Firefox 1.0 browser shuts down when I try to use the Back button on these pages. Is there some setting in Windows XP that is causing this or is there something I can add to the Javascript to...
6
4038
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": window.onload = function() { var audObj = document.createElement("object"); audObj.setAttribute("id", "objmedia"); audObj.setAttribute("type","audio/x-aiff"); audObj.setAttribute("data","media/aif_sample.aif");
0
1946
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) Copyright 1981-2001 Microsoft Corporation PCM 22.050 kHz, 8 Bit, Mono If I double-click the icon-looking thing on the form after setting its .Enabled property to true AND its .Verb property to -2, the Microsoft
22
3738
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 type in c:\MyApp\MyHelp\Help1.wav, Windows Media Player tries unsuccessfully to play the wav file. It err's saying ClassFactory cannot supply the requested class. But WMP has no problem at all playing c:\windows\system32\ ALSNDMGR.WAV. That goes...
6
18959
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
3586
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 internet SoundPlayer Class but unfortunately I can't find it in my Visual Studio Application. Whenever I try to use it Dim Player New SoundPlayer ...
4
1521
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 looping the current track? Im kinda new to this. thanks in advance =) These are my codes: var sound1="sounds/2001spce.mid" var sound2="sounds/20fox.mid" var sound3="sounds/9010v2.mid" var sound4="sounds/adam.mid" var...
26
3877
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 almost no posts from the last 3 years: http://groups.google.com/group/comp.lang.javascript/search?group=comp.lang.javascript&q=how+to+play+a+sound+with+Javascript&qt_g=Search+this+group Even after sorting by date, there don't appear any...
8
14932
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 cut and paste code that MSDN recommends for playing a simple wav file from inside an embedded file, like presumeably the 'resources' file .resx is. I want to embed the .wav file in a 'resource file' since I don't want the user storing the file on...
0
8162
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8605
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8565
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8246
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8415
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6076
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4045
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
1413
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.