VBA example - Microsoft Access-video player


Video player with Media Player

ms access video player

To create a video player with Ms. Access 2007  as shown above, you need to open and Ms. Access 2007 application database and create a form and name it Playnow. On this form, you will drop three buttons( Play, Stop, and Add), and one list box to display selected attached file. You also need to add Window Media Player Activex control from Control group of Design menu. After naming these controls (you have to name them as used in the code below. Otherwise, it doesn't work), use the following code:

Option Compare Database
Option Explicit
Dim i As Integer
Dim wp As WindowsMediaPlayer
Private Sub Command1_Click()
On Error Resume Next
If wp.playState = wmppsPlaying Then 'stop playing
wp.Close
End If
End Sub

Private Sub Command2_Click()
On Error Resume Next
lstfile.Selected(0) = True 'select the first item
lstfile.ListIndex = 0
i = lstfile.ListIndex
wp.URL = lstfile.Column(0, 0) 'play the first item


End Sub


Private Sub Command6_Click()

'set listbox's rowsourcetype
lstfile.RowSourceType = "Value List"
'clear listbox
lstfile.RowSource = ""
'reset i
i = 0
Dim fdialog As Office.FileDialog
Dim fs As Variant
'create filedilog object
Set fdialog = Application.FileDialog(msoFileDialogFilePicker)

With fdialog
'add filters
.Filters.Add "Ms.Access Files", "*.avi; *.mp4; *.dat; *.mp3; *.m4; *.wmv; *.wm; *.wma; *.asf", 1
.InitialFileName = CurrentProject.Path
If .show Then
'loop through selected items
For Each fs In .SelectedItems

lstfile.AddItem fs 'add to listbox

Next fs
Else
End If
End With
'clear filedialog object
Set fdialog = Nothing
End Sub



Private Sub Form_Load()
'create w media object
Set wp = wplayer.Object

End Sub

Private Sub Form_Timer()
'play all items in the list continuously
If wp.playState = wmppsStopped Then
i = i + 1
If i < lstfile.ListCount Then
lstfile.Selected(i) = True
wp.URL = lstfile.Column(0, i)
End If
End If
End Sub

Private Sub Form_Unload(Cancel As Integer)
Set wp = Nothing
End Sub

Private Sub lstfile_BeforeUpdate(Cancel As Integer)
On Error Resume Next
'play the item selected manually
wp.URL = lstfile.Column(0, lstfile.ListIndex)
'update i
i = lstfile.ListIndex
End Sub


Comments

Rudolf comment

 Rudolf

The correct way to use download the video player file on your computer copy the form without opening it, if it's you cannot copy it,
Now open your own database and paste the from under forms,
Click on on the form to open it in design mode right click on white window, click on the tools menu
click preferences activate Microsoft office 14.0 Object library
That is't close window and click on add to add a video


2016-08-25
Rudolf comment

 Rudolf

To use this video player code in your own access database you have to activate Microsoft office 14.0 Object Library under tools references


2016-08-25
Rudolf comment

 Rudolf

To use this video player code in your own access database you have to activate Microsoft office 14.0 Object Library under tools references


2016-08-25
Rudolf comment

 Rudolf

I am having a code problem with
video player example in ms 2010
Dim fdialog As Office.FileDialog
Do you have to activate of special file in the tools references menu for this dialog to work which files


2016-08-04
john comment

 john

hello guys, my name is john. i want template of a simple database in ms access that can rand students score for me. example, mark=98. rank= 1st . mark= 88 . rank =2nd etc . where the rand will automatically populate.


2015-02-16
john comment

 john

hello guys, my name is john. i want template of a simple database in ms access that can rand students score for me. example, mark=98. rank= 1st . mark= 88 . rank =2nd etc . where the rand will automatically populate.


2015-02-16
access_begin comment

 access_begin

Thnak you Dara


2014-09-04
Dara comment

 Dara

The complete code of Video Player application in Access 2007 is in this page: http://www.worldbestlearningcenter.com/index_files/Access_2007_download.htm.


2014-05-17
BJROYHANN comment

 BJROYHANN

This player is crap it needs more instruction. The list just keeps deleting without any play.


2014-05-16
Dara comment

 Dara

At the bottom of the page: index_files/vba-examples-microsoft-access.htm you can find the download link.


2013-10-09
anchamal comment

 anchamal

can you provide this code in an mdb file?


2013-10-09
anchamal comment

 anchamal

using office 2013
1. i copied and paste your code
2. named my form Playnow
3. created three buttons "play" (command1), "stop" (command2), "add" (command6)"
4. placed listbox and named as "lstfile"
5. placed windows mediaplayer and named as "wp"

when i run i get Error Message: Member Already Exists in an Object Module from Which This Object Module Derives


2013-10-08



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.