En Access 2.0, incluye estas dos lineas en la sección Declaraciones de un módulo:
Declare Function sndPlaySound Lib "mmsystem" (ByVal lpszSoundName As String, ByVal uFlags As Integer) As Integer
Declare Function mciSendString Lib "mmsystem" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Integer, ByVal hWndCallback As Integer) As Long
Y también la siguiente función:
Function myPlaySound (fichero, tipo)
Dim l As Long
Select Case tipo
Case "wav"
l = sndPlaySound(fichero, 1)
Case "mid"
l = mciSendString("close mymid", "", 0, 0) ' detiene mymid si estaba en play
l = mciSendString("open " & fichero & " type sequencer alias mymid" & Chr(0), "", 0, 0)
l = mciSendString("play mymid", "", 0, 0)
End Select
End Function
Para reproducir un sonido, solo tienes que llamar a la función myPlaySound pasandole el path completo del fichero (o el nombre de un sonido del sistema) y el tipo, wav o mid.
Para Access 7.0, 97 y 2000, estas son las Declaraciones:
Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" (ByVal filename As String, ByVal snd_async As Long) As Long
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
Y esta es la función:
Function myPlaySound (fichero, tipo)
Dim l As Long, lpszShortPath As String, cchBuffer As Long, corto As Long
lpszShortPath = String(255, Chr(0)): cchBuffer = 255
corto = GetShortPathName(fichero & Chr(0), lpszShortPath, cchBuffer)
Select Case tipo
Case "wav"
l = sndPlaySound(fichero, 1)
Case "mid"
l = mciSendString("close mymid", "", 0, 0) ' detiene mymid si estaba en play
l = mciSendString("open " & Left(lpszShortPath, corto) & " type sequencer alias mymid" & Chr(0), "", 0, 0)
l = mciSendString("play mymid", "", 0, 0)
End Select
End Function