Results 1 to 4 of 4
  1. #1
    New Lounger
    Join Date
    Sep 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sounds on Access Forms (Access 2000)

    I have a table with an embedded picture in one field and an embedded .wav file in another. In a form I am trying to make the .wav file play when someone clicks a button. I know that you can activate the OLE object by double clicking on it but it is hidden on the form. For example the first field is a jpeg of a cow and the second field is a .wav file that says moo. When the user goes to that record in the form I would like it to say moo when the user clicks the button. If anyone knows about this I would appreciate any help.

    Eric

  2. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,436
    Thanks
    1
    Thanked 34 Times in 34 Posts

    Re: Sounds on Access Forms (Access 2000)

    If you have the "Access Developer's Handbook" by Litwin, Getz, and Gilbert, there is code in there allows for some simple control of sounds.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Sounds on Access Forms (Access 2000)

    1) To play an embedded sound, you can use the following code. It assumes that there is a control on the form bound to the OLE field. The control can be hidden. In the example, the control is named objSound, and the command button that plays the sound is named cmdPlay.

    <img src=/w3timages/blueline.gif width=33% height=2>

    Private Sub cmdPlay_Click()
    With objSound
    .Verb = acOLEVerbPrimary
    .Action = acOLEActivate
    End With
    End Sub

    <img src=/w3timages/blueline.gif width=33% height=2>

    2) As an alternative, you might consider not storing the pictures and sounds as embedded objects, but just their path/filenames. Storing pictures in an Access database is a recipe for database bloat. If you do a search for "picture" in this Forum, you'll find lots of threads about this subject. For an example of using paths to pictures in a table instead of embedded pictures, see <post#=126927>post 126927</post#>.

    If you store the path to the sound file in a field named SoundPath, you can play the sound as follows:

    Put the following declarations in a standard module:

    <img src=/w3timages/blueline.gif width=33% height=2>

    Public Const SND_ASYNC = &H1 ' play asynchronously
    Public Const SND_FILENAME = &H20000 ' name is a file name

    Public Declare Function PlaySound Lib "winmm.dll" _
    Alias "PlaySoundA" _
    (ByVal lpszName As String, _
    ByVal hModule As Long, _
    ByVal dwFlags As Long) As Long

    <img src=/w3timages/blueline.gif width=33% height=2>

    Use this in your form:

    <img src=/w3timages/blueline.gif width=33% height=2>

    Private Sub cmdPlay_Click()
    PlaySound Me.SoundPath, ByVal 0&, SND_FILENAME Or SND_ASYNC
    End Sub

    <img src=/w3timages/blueline.gif width=33% height=2>

  4. #4
    New Lounger
    Join Date
    Sep 2002
    Posts
    15
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sounds on Access Forms (Access 2000)

    Thanks that worked great!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •