Solved

Playing WAV files without OLE

Posted on 1998-06-16
1
145 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing parameter in sql procedure 9 63
Copy a row 12 62
Visual Studio search word table and return Cell index 8 61
Send outlook email from VBS Script 2 30
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

777 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