Video player implementation using Access VBA

This article is about video player implementation in MS Access using VBA

We can implement full fledge functionality of a video player in Microsoft Access. But in this article basic functionality have been implemented. In order to implement video player in Microsoft Access first of all we will create basic control over a form. All these controls have been shown in figure Fig 1.1

Video player implementation using Access VBA Fig-1.1


User can load a video file from particular location on disk using Load button. In order to play a video file user can click on Play button. Using Stop button user can stop current video file. In order to load a video file user needs to click on Load button. As response to this click browse window will be in front of user that has been shown in Fig 1.2

Video player implementation using Access VBA Fig-1.2


After selecting particular video file click on OK button as shown in figure Fig 1.2.Now as a response to this selection file path will be shown in right textbox over main window of Access Video Player. This event has been shown in figure Fig 1.3

Video player implementation using Access VBA Fig-1.3


Now everything is ready and file has been loaded in order to run a video file click on Play button. The moment we click over this button video file will execute as it has been shown in figure Fig 1.4

Video player implementation using Access VBA Fig-1.4


If we want to stop execution then press Stop button. Event has been clearly shown in figure Fig 1.5.As shown in figure mention below path is still reflecting there,pressing stop button does not unload video file. That means user can still execute this video file that was loaded previously.

Video player implementation using Access VBA Fig-1.5

VBA Coding for Access Video Player:-

We will use VBA coding to implement Access Video Player and in order to exploit this feature reference needs to set to Window Media Player.

Dim i As Integer
Dim wmp As WindowsMediaPlayer
Private Sub cmdStop_Click()
On Error Resume Next
If wmp.playState = wmppsPlaying Then
wmp.Close 'stop playing
End If
End Sub

Private Sub cmdPlay_Click()
On Error Resume Next
file_path.Selected(0) = True file_path.ListIndex = 0 'select the first item
i = file_path.ListIndex
wmp.URL = file_path.Column(0, 0) 'play the first item
End Sub

Private Sub cmdAdd_Click()
'set listbox's rowsourcetype
file_path.RowSourceType = "Value List"
'clear listbox
file_path.RowSource = ""
'reset i
i = 0
Dim filedlg As Office.FileDialog
Dim fs As Variant
'create filedilog object
Set filedlg = Application.FileDialog(msoFileDialogFilePicker)
With filedlg
'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
file_path.AddItem fs 'add to listbox
Next fs
End If
End With
'clear filedialog object
Set filedlg = Nothing
End Sub

Private Sub Form_Load()
'create w media object
Set wmp = player_box.Object
End Sub
Private Sub Form_Timer()
'play all items in the list continuously
If wmp.playState = wmppsStopped Then
i = i + 1
If i < file_path.ListCount Then
file_path.Selected(i) = True
wmp.URL = file_path.Column(0, i)
End If
End If
End Sub

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

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


It is advised that the information provided in the article should not be used for any kind formal or production programming purposes as content of the article may not be complete or well tested. Access Guru will not be responsible for any kind of damage (monetary, time, personal or any other type) which may take place because of the usage of the content in the article.