Answer: It is possible to play wav files within your Access database. To do this, create a new Module and paste in the following VBA
code:
Const SND_ASYNC = (1)
Const SND_NODEFAULT = (2)
Declare Function sndplaysound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Sub API_PlaySound(pWavFile As String)
Dim LResult As Long
'Make a Windows API call to play a wav file
LResult = sndplaysound(pWavFile, SND_NODEFAULT + SND_ASYNC)
End Sub
Your module should look like this:
![](https://lh4.googleusercontent.com/-RjjgvI3hOoc/T_G94V69HAI/AAAAAAAAGs8/FqerwcXvGAM/s587/play_wav2_001.png)
Next, open your form in Design View and select Properties under the View menu.
![](https://lh6.googleusercontent.com/-EYbTJZnQArw/T_G94sBrEYI/AAAAAAAAGtA/YblCE5uL8Mc/s364/play_wav2_002.png)
When the Properties window appears, select the property called "On Load". A button with 3 dots should appear to the right of the property. Click on this button.
![](https://lh6.googleusercontent.com/-jHHBuE7B7Is/T_G95UuPfwI/AAAAAAAAGtI/EJLdk3b8CSg/s284/play_wav2_003.png)
When the Choose Builder window appears, highlight Code Builder and click on the OK button.
![](https://lh6.googleusercontent.com/-3sjkF9vAWk4/T_G95gXBVZI/AAAAAAAAGtQ/u9thmVYeyrI/s500/play_wav2_004.png)
Now enter the following code in the Form_Load event:
Private Sub Form_Load()
'Play wav file only if category name is beverages
If CategoryName = "Beverages" Then
API_PlaySound "c:\windows\media\chimes.wav"
End If
End Sub
The code above would play the wav file called chimes.wav that is located in the c:\windows\media directory. But the wav file is only played if the text box called CategoryName contains the value "Beverages".
No comments:
Post a Comment