سؤال

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.

هل كانت مفيدة؟

المحلول

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.

نصائح أخرى

Another possibility would be to simply use the DoEvents loop based on wmppsStopped and cut out the Pause function middleman:

Do Until player.playState = wmppsStopped
    DoEvents
Loop

This just keeps a loop going but passes control to the console (so Access and Windows aren't "locked up") until the video hits the end. Just make sure the user can't close the form: remove the control box and make the form modal to ensure they don't hide it.

The only way that would possibly work is if you knew the length of the video. Then you could put an OnTimer event to "put the computer to sleep" for the specified amount of time.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top