Access VBAでサウンドのファイルを3種類の方法で再生します。
使用する「tada.wav」はWindows付属のWAVファイルです。
■mciSendString APIで再生する
Option Compare Database
Option Explicit
Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Private Sub コマンド5_Click()
Dim lRet As Long
lRet = mciSendString("Play c:\notify.wav", "", 0, 0)
End Sub
■PlaySound APIで再生する
Option Compare Database
Option Explicit
Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, _
ByVal dwFlags As Long) As Long
Private Sub コマンド5_Click()
PlaySound "c:\tada.wav", 1, 1
End Sub
■Windows Media Playerで再生する
Option Compare Database
Option Explicit
Private Sub コマンド5_Click()
Shell "mplay32.exe /play /close c:\notify.wav"
End Sub