Solved

Playing WAV files without OLE

Posted on 1998-06-16
1
143 Views
Last Modified: 2012-05-04
I can play WAV files by puting an object on the form and then linking to the WAV file. It can then be played on an event (double click). But I want to play some WAV files on Errors and on opening a form. How can I do this
0
Comment
Question by:cobrapc
1 Comment
 
LVL 9

Accepted Solution

by:
Dalin earned 50 total points
ID: 1463461
cobrapc,
Here are the code for play wav file, any questions, let me know.
Regards
Dalin

 Create a '.BAS' module. Go ahead and name this module 'modPlayWave'.

 Now declare the API functions needed in order to play .WAV files.
 In the General Declarations area of the new module,  enter:

     #If Win32 Then
          Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
          (ByVal lpSound As String, ByVal flag As Long) As Long
     #ElseIf Win16 Then
          Declare Function sndPlaySound Lib "MMSYSTEM" _
          (ByVal lpszSoundName As String, ByVal uFlags As Integer) As Integer
     #End If

 

   Now create a procedure and call it PlayWave. This procedure will accept one parameter
   and that will be the filename of the wave file to be played. Let's call this parameter sFileName.

     
     Sub PlayWave(sFileName As String)

         On Error GoTo Play_Err
         
         Dim iReturn As Integer
         
         'Make sure something was passed to the Play Function
         If sFileName > "" Then
             'Make sure a WAV filename was passed
             If UCase$(Right$(sFileName, 3)) = "WAV" Then
                 'Make sure the file exists
                 If Dir(sFileName) > "" Then
                     iReturn = sndPlaySound(sFileName, 0)
                 End If
             End If
         End If
         
         'Wav file play successful
         Exit Sub

     Play_Err:
         'If there was an error then exit without playing
         Exit Sub

     End Sub

 

Now, in where you want to play the WAV,  add the code:
 
        PlayWave "YourWavFileWithPath"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now