Open a database and sound plays

ddennis

New Member
Joined
Apr 21, 2004
Messages
22
Good day:

I have created a colorful database. I would like the database to play a wav file when it is opened.

Any ideas?

Many thanks,

Dion :pray:
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Copy and paste the code below into a new module

It will play avi,mid and wav extensions and these must be specified in the file name

To test it open the immediate window (ctrl+g) in the VBA window and type

?fPlaySound("C:\Program Files\NetMeeting\Testsnd.wav")

A sound should then be heard

The function is called by placing fplaySound(filename) in your splash screens code.


Option Compare Database
Option Explicit

Private Declare Function apiPlaySound Lib "Winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Private Declare Function apimciSendString Lib "Winmm.dll" Alias "mciSendStringA" _
(ByVal lpstrCommand As String, ByVal lpstrReturnString As String, _
ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

Private Declare Function apimciGetErrorString Lib "Winmm.dll" _
Alias "mciGetErrorStringA" (ByVal dwError As Long, _
ByVal lpstrBuffer As String, ByVal uLength As Long) As Long


Function fPlaySound(ByVal strFilename As String, _
Optional intPlayMode As Integer) As Long

Dim lngRet As Long
Dim strTemp As String

On Error GoTo Err_fPlaySound

Select Case LCase(fFileExt(strFilename))
Case "wav":
If Not IsMissing(intPlayMode) Then
lngRet = apiPlaySound(strFilename, intPlayMode)
Else
MsgBox "Must specify play mode."
Exit Function
End If
Case "avi", "mid":
strTemp = String$(256, 0)
lngRet = apimciSendString("play " & strFilename, strTemp, 255, 0)
End Select
fPlaySound = lngRet

Exit_Err_fPlaySound:
Exit Function

Err_fPlaySound:
MsgBox Err.Description, vbCritical + vbSystemModal, "Error"
Resume Exit_Err_fPlaySound

End Function



Private Function fFileExt(ByVal strFullPath As String) As String
Dim intPos As Integer, intLen As Integer
On Error GoTo Err_fFileExt

intLen = Len(strFullPath)
If intLen Then
For intPos = intLen To 1 Step -1
If Mid$(strFullPath, intPos, 1) = "." Then
fFileExt = Mid$(strFullPath, intPos + 1)
Exit Function
End If
Next intPos
End If

Exit_Err_fFileExt:
Exit Function

Err_fFileExt:
MsgBox Err.Description, vbCritical + vbSystemModal, "Error"
Resume Exit_Err_fFileExt

End Function


HTH

Cheers

Dave
(y)
 
Upvote 0

Forum statistics

Threads
1,221,787
Messages
6,161,960
Members
451,734
Latest member
Anmol Pandey19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top