Windows Media Player

Cheeze83

New Member
Joined
Nov 5, 2012
Messages
20
Hi All

Sorry if this has been posted before, I have been searching all day and had no luck. I have used another source to browse and load a audio file from a form in access, however the problem I am having is with playing the file.

The code I have is:

Code:
Private Sub Command114_Click()' play audio file






  On Error GoTo ErrorHandler


   strAudioFile = Nz(Me![txtSelectedAudioFile].Value)
   If strAudioFile = "" Then
      strTitle = "No file selected"
      strPrompt = "Please select an audio file to play"
      DoCmd.Beep
      MsgBox strPrompt, vbOKOnly + vbCritical, strTitle
      Me![txtSelectedAudioFile].SetFocus
      GoTo ErrorHandlerExit
   Else
      'Check that file name and path is valid
      Debug.Print "Selected audio file: " & strAudioFile
      If FileExists(strAudioFile) = False Then
         strTitle = "Invalid file name"
         strPrompt = "File name and/or path is invalid; please re-select file"
      DoCmd.Beep
         MsgBox strPrompt, vbOKOnly + vbCritical, strTitle
         Me![txtSelectedAudioFile].SetFocus
         GoTo ErrorHandlerExit
      Else
         Set prj = Application.CurrentProject
       
         If prj.AllForms("frmWindowsMediaPlayer").IsLoaded Then
            DoCmd.Close acForm, "frmWindowsMediaPlayer"
         End If
   
         Me.Move Left:=2500, Top:=2500
         With Me![ocxWindowsMediaPlayer]
            .URL = strAudioFile
         End With
      End If
   End If
   
ErrorHandlerExit:
   Exit Sub


ErrorHandler:
   MsgBox "Error No: " & Err.Number & "; Description: " & Err.Description
   Resume ErrorHandlerExit


End Sub

Now, this points to a form that has the windows media player object in it - however; I get the following error

PHP:
Error No: 2465; Description: Microsoft Access can't find the field 'ocxWindowsMediaPlayer' referred to in your expression

However, if I use the source file to do it - it all works perfectly, so I am guessing that my problem is potentially different. Sorry if this is pretty basic - been a long day and I am all out of ideas.
 
Last edited:

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
If you do not provide a "value if null" to NZ, it could return a 0 or zero length string.
strAudioFile = Nz(Me![txtSelectedAudioFile].Value) >> strAudiFile = Nz(Me.[txtSelectedAudioFile],"") assuming you're going to test for "".
Some other suggestions:
Purists will tell you this is bad form GoTo ErrorHandlerExit >> just Exit Sub or Exit Function. I kind of agree.

If FileExists(strAudioFile) = False Then
Do Stuff
End If
In your case, because it is either false or it's not. If it's not, whatever comes next will be processed without a nested portion. Only makes it easier to follow, I guess.

Now for the error. Did you try Me.ocxWindowsMediaPlayer ? Access is likely to see ocxWindowsMediaPlayer as a field because of the brackets. I also removed the !
This I don't get However, if I use the source file to do it... It's good to demonstrate where in code you've tried something.
 
Upvote 0

Forum statistics

Threads
1,221,819
Messages
6,162,155
Members
451,749
Latest member
zack_ken

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top