Media Player ActiveX Control (1 Viewer)

PeterWieland

Registered User.
Local time
Today, 10:41
Joined
Sep 20, 2000
Messages
74
Hi,

I have a form with an ActiveX Control for Media Player 10. The player works ok, but if I try to close the form using the PlayStateChange Event, Access crashes out to the 'Send Report To Microsoft' window.

This is the code:-

Code:
Private Sub WindowsMediaPlayer0_PlayStateChange(ByVal Newstate As Long)

   If Newstate = 8 Then
  
      DoCmd.Close
   
   End If
End Sub

This is looking for the end of the current media file, but I get the same problem if I look for Newstate = 1, the stop button being pressed.

However, if I put the DoCmd.Close command behind a command button, the form closes as normal.

Any ideas?
 

MarkK

bit cruncher
Local time
Today, 02:41
Joined
Mar 17, 2004
Messages
8,183
Not sure if this is the problem, but I never use the DoCmd.Close command without parameters, since it's frequently unclear what will be closed.
To close the form in which code is running, use instead...
Code:
DoCmd.Close acForm, Me.Name
Another possibility...
Code is running in the ActiveX control which generates an event that causes Access to destroy the object that is hosting the control. Stands to reason that this may cause problems for the control, since it's impossible for code there to exit gracefully.
Maybe try to start the timer on the form for, say 100ms, and have the form's on_timer event handler close the form. This would allow the routine that initiated the PlayStateChange event in the control to complete.
 

PeterWieland

Registered User.
Local time
Today, 10:41
Joined
Sep 20, 2000
Messages
74
Thanks for the reply lagbolt.

I've already tried the full parameters for the command, made no difference, nor did setting the focus onto another form before closing.

The timer thing seemed like a good idea, so I gave it a go. Got up to 5 seconds and still crashes out!

I suppose what I need is some way to completely reset the player before closing, but I've searched everywhere and cannot find anything for WMP 10 (plenty of stuff for 7, but I don't have that!)
 

PeterWieland

Registered User.
Local time
Today, 10:41
Joined
Sep 20, 2000
Messages
74
I have just tried this in Visual Basic 6.0, and it works. My conclusion is that it is something to do with the way the VBA Close command works, which is different to the VB Unload command. There doesn't seem to be any documentation available that describes what happens when you invoke these commands!
 

Users who are viewing this thread

Top Bottom