Results 1 to 3 of 3
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Sounds on a Form (Access 2003)

    How do I get a sound(.WAV file) to play when a form is opened?


    Thanks
    Richard

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

    Re: Sounds on a Form (Access 2003)

    Put the following declaration at the top of a standard module (below Option Declare Database and Option Explicit, but above all Subs and Functions:
    <code>
    Private Declare Function sndPlaySound Lib "winmm" Alias "sndPlaySoundA" _
    (ByVal filename As String, ByVal snd_async As Long) As Long
    </code>
    Put the following function somewhere below it in the same module:
    <code>
    Public Function PlaySound(sWavFile As String)
    ' Purpose: Plays a sound.
    ' Argument: the full path and file name.

    If sndPlaySound(sWavFile, 1) = 0 Then
    MsgBox "The Sound Did Not Play!", vbExclamation
    End If
    End Function
    </code>
    Call the function like this in the On Load event of the form:
    <code>
    Private Sub Form_Load()
    Call PlaySound("C:WindowsMediaChimes.wav")
    End Sub
    </code>
    Substitute the path and filename of the .wav file you want to play.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    USA
    Posts
    386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Sounds on a Form (Access 2003)

    This works just as I had hoped.

    Thanks Hans
    Richard

Posting Permissions

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