Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2015
    Posts
    15

    Unanswered: Problems playing an audio file whose name is in a control of a form

    Hello

    Please, i'm having problems playing an audio file whose name is in a control of a form.

    I created a button in a subform. The action that i expect to happen when i click this button is the following: i expect Windows Media Player to open the mp3 file whose name is in a control of the same subform. I don't know SQL, but i found a code somewhere sometime ago and it was working at that time. Now i created a new Database (wanting to re-use the code) and i think i did the correct adjustments to the code.

    The problem is that it opens Windows Media Player, but the player says that the file selected to be played has the extension (.) wich is unknown to the player. It asks me if i want it to play the file anyway. I click "yes", but it fails.

    Please help me to understand what is going wrong. This is the code:

    Private Sub Command13_Click()
    On Error GoTo Err_Command13_Click

    Dim stAppName As String

    stAppName = "C:\Program Files\Windows Media Player\wmplayer.exe" & " C:\Music - Selected\Outros\" & Me!Link_Imagem_em_Texto & ".mp3"
    Call Shell(stAppName, 1)

    Exit_Command13_Click:
    Exit Sub

    Err_Command13_Click:
    MsgBox Err.Description
    Resume Exit_Command13_Click

    End Sub

    Thank you very much for the atention and for willing to help!

    Regards,
    Marco

  2. #2
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    Don't use a shell process to start the desired application, use the ShellExecute function instead:
    Code:
    Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
                                 (ByVal hwnd As Long, ByVal lpszOp As String, _
                                  ByVal lpszFile As String, ByVal lpszParams As String, _
                                  ByVal LpszDir As String, ByVal FsShowCmd As Long) As Long
    
    Sub OpenFile(ByVal FilePath As String)
    
        Const SW_SHOWNORMAL As Long = 1
        
        ShellExecute 0, "open", FilePath, vbNullString, vbNullString, SW_SHOWNORMAL
    
    End Sub
    Example:
    Code:
    OpenFile "U:\Music\Clannad\The Ultimate Collection\Nil Sen La.mp3"
    Have a nice day!

  3. #3
    Join Date
    Nov 2015
    Posts
    15
    Thank you very much for the reply!

    I was not able to find how to use your code. If it's possible, please let me know exactly where i should put each of the 3 pieces of code you sent me. I understand i have a subroutine Command13_Click() to create. I understand you sent me 3 things:

    1) the "declaration" of a function called "ShellExecute"
    2) A Sub called "OpenFile" that uses this function
    3) A line of code that uses the sub "OpenFile"

    What i have to start to create the procedure that will be called when i click the button is:

    Private Sub Command13_Click()
    End Sub

    Thank you very much!

    Marco

  4. #4
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    1. You copy the code in a standard module (new or existing).

    2. You call it from wherever you want :
    Code:
    Private Sub Command13_Click()
    
        OpenFile "MyFileName.Ext"
    
    End Sub
    Have a nice day!

  5. #5
    Join Date
    Nov 2015
    Posts
    15
    It worked!!! Thank you very very much!

    I will let the thread as "not answared" for the next days, because i still have a "no sense" problem: It works perfectly in a "Test Database", but when i copy it to another "Test - Database", it doesn't work anymore. So i still may need some help in a few days when i will be finishing the creation of the Database.

    Regards,
    Marco

  6. #6
    Join Date
    Mar 2009
    Posts
    5,442
    Provided Answers: 14
    You're welcome!
    Have a nice day!

Posting Permissions

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