Access Form question
-
I've a problem when using a command control in a form who is linked to a code that opens a executable program (Windows Media Player) and a Mp3's file. The Mp3's file is located in a folder that has spaces on it. The problem is the file doesn't open and the WMPlayer sends a message (file extension not recognized). I know that the problem is in the spaces in the folder. Tanks a lot. Here is the code: Private Sub cmdPlay_Click() On Error GoTo Err_cmdPlay_Click Dim stAppName As String Dim PlayFullName As String PlayFullName = "G:\MP3\045- Mp3\test.mp3" stAppName = "D:\Program Files\Windows Media Player\wmplayer.exe " & PlayFullName Call Shell(stAppName, vbMinimizedFocus) Exit_cmdPlay_Click: Exit Sub Err_cmdPlay_Click: MsgBox Err.Description Resume Exit_cmdPlay_Click End Sub
-
I've a problem when using a command control in a form who is linked to a code that opens a executable program (Windows Media Player) and a Mp3's file. The Mp3's file is located in a folder that has spaces on it. The problem is the file doesn't open and the WMPlayer sends a message (file extension not recognized). I know that the problem is in the spaces in the folder. Tanks a lot. Here is the code: Private Sub cmdPlay_Click() On Error GoTo Err_cmdPlay_Click Dim stAppName As String Dim PlayFullName As String PlayFullName = "G:\MP3\045- Mp3\test.mp3" stAppName = "D:\Program Files\Windows Media Player\wmplayer.exe " & PlayFullName Call Shell(stAppName, vbMinimizedFocus) Exit_cmdPlay_Click: Exit Sub Err_cmdPlay_Click: MsgBox Err.Description Resume Exit_cmdPlay_Click End Sub
The problem is the spaces, your right. But solution is also pretty easy. The problem comes because the spaces are seen as command-line argument seperators. This is the command-line your sending to Shell:
D:\...\wmplayer.exe g:\mp3\045- mp3\test.mp3
Your actually telling wmplayer that there are 2 command-line parameters:
'g:\mp3\045-' and 'mp3\test.mp3'
The solution is to put quotes around both parts of the command-line:
PlayFullName = chr$(34) & "G:\MP3\045- Mp3\test.mp3" & chr$(34)
stAppName = chr$(34) & "D:\Program Files\Windows Media Player\wmplayer.exe" & chr$(34) & " " & PlayFullNameNow your sending the command-line as:
"D:\...\wmplayer.exe" "G:\mp3\045- mp3\test.mp3"
The quotes will prevent the spaces from becoming argument seperators. RageInTheMachine9532