Hi Bernd,
This example assumes you are familiar with Visual Basic for Applications ,
win32 API calls, and how to use modules in Access. The following
example will show the win32 API call and samples of a module and how to use
different arguments. You can get win32 API calls from Visual Basic 4.0 or
from
the Win32 Source Development Kit (SDK).
1.Start Microsoft Access and open the sample database Northwind.MDB.
2.Click on the Modules tab. Then click on the "New" button.
3.The following line needs to be type in the Declarations Section of the
new module.
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA"_
(ByVal lpszsoundname As String, ByVal uflags As Long) As Long
4.Compile and save the module.
5.Open the Categories form in design view. Right mouse click on the category
name control to call up the properties for that control.
6.Click on the "On Enter" event. Click the Button with the 3 dots and Double
click "Code Builder".
7.Enter the following code:
Dim ret as long
ret = sndPlaySound("chimes.wav",0) '(Wave file must be in your_ windows
directory)
8.Click "Run" and the "Compile Loaded Modules" from the main menu. Save the
form and then close the form.
9.Open the Categories form in "Form View". You will here the Chimes sound
everytime you "Enter" or "Tab" into the "CategoryName" field.
The first argument you pass is the filename you wish to play. The second
argument can be one or more of the following added together (and a few other
things too):
SND_SYNC 0x0000
SND_ASYNC 0x0001
SND_NODEFAULT 0x0002
SND_MEMORY 0x0004
SND_LOOP 0x0008
SND_NOSTOP 0x0010
These values are from MMSYSTEM.H in the Windows SDK. They are in hex. Here
is
what they mean:
SND_SYNC (0) plays the requested sound synchronously, that is, sndPlaySound
will wait until the sound is played before returning.
SND_ASYNC (1) plays the requested sound asynchronously, that is, it will
return immediately once it starts playing the sound. This is how you can
play
a sound behind some other action.
SND_NODEFAULT (2) tells the function not to play the default beep if the
sound
file is not found.
SND_MEMORY (4) says that you are passing a memory address to the function as
the first argument rather than the filename.
SND_LOOP (8) must be used with SND_ASYNC. It means to repeat the sound over
and over again. You must issue another sndPlaySound() call to stop the
sound.
SND_NOSTOP (16) means to return False if a sound is currently playing.
Examples:
'play sound asynchronously
ret = sndPlaySound("c:\w\chimes.wav", 1)
'play chimes, don't play default beep if file not found
ret = sndPlaySound("chimes.wav", 3)
'play chimes repeatedly, don't play default beep if file not found
ret = sndPlaySound("chimes.wav", 10)
I hope this helps
Mark
This information is provided "as is", and confers no rights or expresses
any warranties.