In Over My Head: Send command to launch Media Player

  • Thread starter Thread starter David
  • Start date Start date
D

David

When double clicking on a value for a field in my
database "mydatabase.mdb" from a Form, I want the Windows
Media player to open and play the file I have double
clicked on.

Ive gotten the player to launch by creating a Macro event
with the following command line:

C:\Program Files\Windows Media Player\wmplayer.exe

But how do I pass it a value from the database ?

TIA

-David
 
David said:
When double clicking on a value for a field in my
database "mydatabase.mdb" from a Form, I want the Windows
Media player to open and play the file I have double
clicked on.

Ive gotten the player to launch by creating a Macro event
with the following command line:

C:\Program Files\Windows Media Player\wmplayer.exe

But how do I pass it a value from the database ?

I'm not sufficiently familiar with macros to know if you can do this
with a macro, but I'd write a VBA event procedure to do this, and either
use Application.FollowHyperlink (if the file type is associated with
Media Player) or use the Shell function to run an appropriately
constructed command line. For example:

'--- EXAMPLE 1 ---
' Use this if the file type is associated with Media Player.
Private Sub Text0_DblClick(Cancel As Integer)
Application.FollowHyperlink Me.Text0
End Sub
'--- end EXAMPLE 1 ---

'--- EXAMPLE 2 ---
' Use this if you need to explicitly invoke Media Player.
Private Sub Text0_DblClick(Cancel As Integer)

Dim strCommandline As String

strCommandline = _
"C:\Program Files\Windows Media Player\wmplayer.exe " & _
Chr(34) & Me.Text0 & Chr(34)

Shell strCommandline, vbNormalFocus

End Sub

'--- end EXAMPLE 2 ---

The above examples assume that Text0 is the name of the text box
containing the path to the file; obviously you would need to change
Text0 to the name you are using.
 
David said:
Thanks very much Dirk.

This seems to almost work. However, the media player needs
to know where to find the file to play. The database is
in, say, d:\work\mydatabase.mdb. The file to launch is in
d:\work\files\. The files are associated with the Media
Player.

So, the database is really one table that has the list of
media files. I want, via my form, to click on the file
name and launch the file via Media Player. I think Im just
missing a path statement.

So you're saying the table field contains just the file name, and all
the files are in the same folder? Then modify the "FollowHyperlink"
version like this:

--- start of code ---
Private Sub Text0_DblClick(Cancel As Integer)

Application.FollowHyperlink "D:\Work\Files\" & Me.Text0

End Sub
--- end of code ---
 
Fantastic!

Now, for the final touch, Ive got the Media Player embeded
in the Form. Is there a way to have the file play via the
player that is embedded (so that I can easily access the
player controls from within the Form)

Thanks for all your help.
 
David said:
Fantastic!

Now, for the final touch, Ive got the Media Player embeded
in the Form. Is there a way to have the file play via the
player that is embedded (so that I can easily access the
player controls from within the Form)

Thanks for all your help.

Ah, that's another matter. I've never done this before, but a little
experimentation suggests that executing a code statement like this:

Me.MediaPlayer0.FileName = "D:\Work\Files\" & Me.Text0

ought to work. The Media Player object also has an AutoStart property
that governs whether the file begins playing immediately.
 
Back
Top