play a video via ms access form

Posted on 2009-04-24
Last Modified: 2012-05-06
How can I play a video via ms access form?
Question by:M_SOLAIMAN
    LVL 65

    Accepted Solution

    Simple example without creating a control but doing it in vba

    add a windows media player reference (via Tools/References from vba editor)

    define a form level variable then create buttons to play and stop

    you have a variable called wmp and you create buttons to allow playing

    define in form (near top)

    Dim wmp As WindowsMediaPlayer

    Now you need to initialise when the form loads and close it down when form closes

    Private Sub Form_Load()
        Set wmp = New WindowsMediaPlayer
    End Sub

    Private Sub Form_Close()
        Set wmp = Nothing
    End Sub

    To play a video, you can do this

    'Use this line to clear current play list

    'Add this to playlist - special mention to one of the top experts here DatabaseMX
        wmp.currentPlaylist.appendItem m_WMP.newMedia(c:\DatabaseMXDoesntWatchPronHonest.avi")

    'Start play

    to stop, you got to do this

    LVL 28

    Assisted Solution

    If this is a file then you can shell windows media player and pass the file to it. To run the function then you can set the OnClick event to

    =PlayVideo("C:\Users\Public\Videos\Sample Videos\Lake.wmv")

    Cheers, Andrew
    Function PlayVideo(pstrFile As String)
    Dim strPlayer As String
        strPlayer = Chr(34) & "C:\Program Files\Windows Media Player\wmplayer.exe" & Chr(34)
        Shell strPlayer & " " & Chr(34) & pstrFile & Chr(34), vbMaximizedFocus
    End Function

    Open in new window


    Author Closing Comment

    thanks a lot

    Author Comment

    "Chr(34)" what dose it mean please ?
    LVL 28

    Expert Comment

    The CHR() function returns a charcter represented by the ASCII value, 34 is the double quote character " and as you need this in the string it is the easiest way to read the code

    strPlayer = Chr(34) & "C:\Program Files\Windows Media Player\wmplayer.exe" & Chr(34)

    the above could be written as
    strPlayer = """C:\Program Files\Windows Media Player\wmplayer.exe"""

    Cheers, Andrew

    Author Comment

    thanks a lot "Andrew"

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
    Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
    In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
    Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now