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:
Next, open your form in Design View and select Properties under the View menu.
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.
When the Choose Builder window appears, highlight Code Builder and click on the OK button.
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