What would the code be to have a .mp3 (embedded or a set path) to start playing when the database is opened? Just looking to add a little pizazz to the database.
P.S. There is only one form which is set to automatically open.
What would the code be to have a .mp3 (embedded or a set path) to start playing when the database is opened? Just looking to add a little pizazz to the database.
P.S. There is only one form which is set to automatically open.
This might work: http://allenbrowne.com/func-04.html
I'm very new to this, what do I have wrong?
Private Sub Form_Load()
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
(ByVal filename As String, ByVal snd_async As Long) As Long
Function PlaySound(sWavFile As String)
' Purpose: Plays a sound.
' Argument: C:\users\ocelco70\Desktop\escape.wav
If apisndPlaySound(sWavFile, 1) = 0 Then
MsgBox "The Sound Did Not Play!"
End If
End Function
End Function
Put the PlaySound() function in a Standard Module as Public. Then call it from the OnLoad event of your form with the name of the file you want to play as it shows in the link.
Again, sorry for the ignorance but I know little to nothing about VBA Coding...yet. How do I call the file name from the Sub Form_Load()?
Private Sub Form_Load()
escape.wav
End Sub
Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
(ByVal filename As String, ByVal snd_async As Long) As Long
Function PlaySound(sPublic As String)
' Purpose: Plays a sound.
' Argument: C:\users\ocelco70\Desktop\escape.wav
If apisndPlaySound(sPublic, 1) = 0 Then
MsgBox "The Sound Did Not Play!"
End If
End Function
End Function
Start by creating a *new* module named SOUNDS and in it put the following:
...in the OnLoad event you will then have:Code:Option Compare Database Option Explicit Declare Function apisndPlaySound Lib "winmm" Alias "sndPlaySoundA" _ (ByVal filename As String, ByVal snd_async As Long) As Long Function PlaySound(sWavFile As String) ' Purpose: Plays a sound. ' Argument: the full path and file name. If apisndPlaySound(sWavFile, 1) = 0 Then MsgBox "The Sound Did Not Play!" End If End Function
Code:Private Sub Form_Load() PlaySound("C:\users\ocelco70\Desktop\escape.wav") End Sub
Awesome! Works perfectly, thanks a million man.
Outstanding! Go ahead and follow the link in my sig and mark this thread as Solved.