Consulting

Results 1 to 3 of 3

Thread: run .wav application

  1. #1
    VBAX Newbie
    Joined
    Jan 2005
    Posts
    1
    Location

    run .wav application

    I am trying to open an audio file from a form in access -- is it possible to open a .wav file with a button? I have used the GetObject method to open excel files, but can't get it to run a .wav file on Windows Media player, and am unsure if this can work anyway. I'm open to any suggestions.

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    We should be able to do this.

    First open the VBE and Insert a Module. Then paste in this code.
    [vba]
    Option Compare Database
    Option Explicit

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

    Function PlayWav()

    'Change the file path of the wav file as needed.
    Call PlaySound("C:\WINDOWS\Media\chimes.wav", 0&, &H1 Or &H20000)

    End Function
    [/vba]
    Then close the VBE and go to Access. Click on Macros and then New. For the Action dropdown select RunCode. And for the Function Name field type in PlayWav (). Then close and save the macro.

    Go to your form and add a Command Button. In the Command Button Wizard select Miscellaneous and Run Macro then press Next. Then select the macro from the list and press Next. Finish the rest of the wizard.

    The Command Button should now play the wav file when clicked.

    An example attachment has also been posted.

  3. #3
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Now if you realy want to play the wav file with Windows Media Player try this code.
    [vba]
    Option Compare Database
    Option Explicit

    Declare Function ShellExecute Lib "shell32.dll" _
    Alias "ShellExecuteA" ( _
    ByVal hWnd As Long, _
    ByVal lpOperation As String, _
    ByVal lpFile As String, _
    ByVal lpParameters As String, _
    ByVal lpDirectory As String, _
    ByVal nShowCmd As Long) As Long

    Function OpenAnyFile()

    Dim FilePath As String
    Dim FileName As String
    Dim FileToOpen As String

    FilePath = "C:\WINDOWS\Media"
    FileName = "chimes.wav"
    FileToOpen = FilePath & "\" & FileName

    Call ShellExecute(0, "Open", FileToOpen & vbNullString, _
    vbNullString, vbNullString, 1)

    End Function
    [/vba]
    Note that this will open the wav file with its associated program in Windows. So this will open Windows Media Player so long as that is the default program for playing wav files.

Posting Permissions

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