Search code examples
ms-accessvbams-access-2010wmp

How to perform vba task after media player finishes


I'm using Access 2010 and have tables setup to identify a particular video file. I have a button on a form that will launch the video file with WindowsMediaPlayer. The problem is that I want to update the table(s) after the video has run. I've created this quick from a button on a form (fTest1) but the next part I've been searching around for a while.

Private Sub Command1_Click()
Dim player As WindowsMediaPlayer

DoCmd.OpenForm "fTest2"

Set player = Forms!fTest2!WMP.Object
Forms!fTest2!WMP.URL = "S:\Training Videos\Wildlife.wmv"

' here is where I want to do something after the file has finished
' 

I did a test with a msgbox but it shows up while the video is playing. Looking for like a call or wait until or something.

Any help would be appreciated.


Solution

  • After stumbling around testing I found a post at access-programmers.co.uk by a ghudson for the following function.

    Public Function Pause(NumberOfSeconds As Variant)
    On Error GoTo Err_Pause
    
    Dim PauseTime As Variant, start As Variant
    
    PauseTime = NumberOfSeconds
    start = Timer
    Do While Timer < start + PauseTime
    DoEvents
    Loop
    
    Exit_Pause:
    Exit Function
    
    Err_Pause:
    MsgBox Err.Number & " - " & Err.Description, vbCritical, "Pause()"
    Resume Exit_Pause
    
    End Function
    
    Private Sub Command1_Click()
    Dim player As WindowsMediaPlayer
    Dim VideoDone As String
    
    DoCmd.OpenForm "fTest2"
    
    Set player = Forms!ftest2!WMP.Object
    Forms!ftest2!WMP.URL = "S:\Training Videos\Wildlife.wmv"
    
    VideoDone = "No"
    Pause 5
    
    Do While VideoDone = "No"
    Pause 2
    If player.playState = wmppsStopped Then VideoDone = "Yes"
    Loop
    
    player.Close
    DoCmd.Close acForm, "fTest2"
    
    End Sub
    

    The button is on a test form called "fTest1". I get no "not responding" or busy "circles". Works like a charm.