Solved

Visual Basic question

Posted on 1997-07-05
1
200 Views
Last Modified: 2013-11-25
Am I missing something, or is it a W95 problem...

When I have an embedded OLE object in my database, and it is pulled up into an OLE container in my form, I can open all others that I've tried - Excel, Visio, Notepad, MIDI, BMP etc...

BUT if the embedded document is a WAV file, I get an 'OLE Automation Error' message box, an error 'beep' then the sound plays.

About 50% of the time, my app is tied up after I clear the message box.

I obviously suspect the SNDREC32 app, but does anyone have anything specific, or a solution to this ?

Regards
MC

mcoop@pop.jaring.my
0
Comment
Question by:mcoop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
acidos earned 70 total points
ID: 1428019
 This is a common problem.  Forget trying to OLE in a WAV file, do this:

1) Open your programs module file (or create one if it doesn't have one), and then insert this:

Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Public Declare Function waveOutGetNumDevs Lib "winmm" () As Long

Global Const SND_SYNC = &H0 'just after the sound is ended exit function
Global Const SND_ASYNC = &H1 'just after the beginning of the sound exit function
Global Const SND_NODEFAULT = &H2 'if the sound cannot be found no error message
Global Const SND_LOOP = &H8 'repeat the sound until the function is called again
Global Const SND_NOSTOP = &H10 'if currently a sound is played the function will return without playing the selected sound

Global Const Flags& = SND_ASYNC Or SND_NODEFAULT


2) Create a public sub in the general declarations part of the same module with a name like Play, Sound, Wav, ect. and enter this code into it:

Public Sub Play(SoundFileName As String)
    Dim Crapper As Long
    Crapper = waveOutGetNumDevs()
    If Crapper > 0 Then   'There is at least one sound device.
    Crapper& = sndPlaySound(SoundFileName, Flags&)
    Else
      Beep
    End If

End Sub

3) To play a wav file just type Play(path).  ie: to play a wav file in directory c:\media named sound.wav you would type:

Play("c:\media\sound.wav")

NOTE: Commands after this procedure call are executed BEFORE the wav file is finished playing.  If you want to wait for the wav file to stop playing before the code continues, you need 2 things:

1) The estimated time in seconds (rounded down) of the wav file [this example only works if the wav file is less than 60 seconds. Feel free to modify this code if you wish]

2) Create a new public sub in yer module like Pause.  ie:

Public Sub Pause(Numb As Integer)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'
'               Pauses for a specific amount of seconds
'
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim tot As Integer
    Dim now As String
    Dim lat As String
    now = Time
    now = Left(now, Len(now) - 3)
    now = Right(now, Len(now) - 5)
    lat = Int(now) + Numb
    If lat > 60 Then lat = lat - 60
    Do While tot <> lat
        now = Time
        now = Left(now, Len(now) - 3)
        tot = Right(now, Len(now) - 5)
    Loop
End Sub


  Now, to pause for x amount of seconds, simply type Pause(x).  ie:  to pause for 5 seconds type:

Pause(5)

  To play a sound file c:\media\sound.wav which lasts 15.x seconds and to have the program wait till the sound file is done playing before executing the other code, type:

Play("c:\media\sound.wav")
Pause(15)

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

749 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