Hi, you can use this code:

'First add the ActiveX MMControl

Option Explicit

Private Sub Form_Load()

Dim AppPath As String

    'Appointment of music file from within your program

    If Right$(App.Path, 1) <> "\" Then
        AppPath = App.Path & "\Sound.wav"
    Else
        AppPath = App.Path & "Sound.wav"
    End If
    
    'Determine the type of music file

    MMControl1.DeviceType = "waveaudio"
    
    'If the file type " MIDI "
    'MMControl1.DeviceType = "Sequencer"
    
    'Determining file name

    MMControl1.FileName = AppPath
    'Opening the file

    MMControl1.Command = "open"
    'Reading file

    MMControl1.Command = "play"
    
End Sub


Private Sub MMControl1_Done(NotifyCode As Integer)

    'This event at the end of passage voice

    'Re-reading passage voice
    MMControl1.Command = "prev"
    'Reading passage voice again
    MMControl1.Command = "play"
    
End Sub

hi !!! could you tell me how to make this code point to exactly where the file located , for i.e, D:\...\sound.wav

AppPath = App.Path & "\Sound.wav"

In the code by myself placing the music file is in the same folder that contains your program.
E.g:

If your program in this directory:- "D : \ My Project \ test.exe \", it must be the music file in the following directory :- "D : \ My Project \ song.wav"

I hope that this is clear.

The inter ( app.path ) it means:

The music file, or any other file must be in the same program directory

This article has been dead for over six months. Start a new discussion instead.