Set fd = Application.FileDialog(msoFileDialogFolderPicker) ‘Create a FileDialog object as a Folder Picker dialog box. Note that you have to iterate through the selections in the dialog, even though you are in fact only allowed to select one folder. The button’s Click event procedure uses the Office FileDialog object (introduced in Office XP) to put up a Folder Picker dialog the selected folder name is stored in the txtMediaPath folder, which is bound to the MediaPath field in tblInfo (I use a table to store the selections on the form, so they will persist from session to session). The first button, cmdSelectMediaPath, lets you select a folder where you store your media files – if a folder is selected, it will be used as the initial folder for the cmdSelectAudioFile and cmdSelectVideoFile buttons. An Access form for selecting and playing audio and video files The form footer has buttons to play the audio file, play the video file, and close the form.įigure A. I made a form (frmSelectFile, shown in Figure A) with three command buttons in the Detail section, with associated textboxes, for selecting the default media path (this is optional), an audio file, and a video file. I found that if I made the control invisible (to play audio files without an interface), it was invisible in design view as well as form view, and even if I changed the uiMode property back to “full”, the control remained invisible, and I had to delete and reinsert it to have a visible control once more. The uiMode property (which lacks a dropdown list for selecting the available choices – again, typical of ActiveX controls on Access forms) takes either “full” (the Windows Media Player interface is visible) or “invisible” (the control is invisible). Most unintuitively, the URL property takes, not a URL as you would expect, but a standard file path and name, such as “C:My DocumentsMedia FilesSpeech.mp3”.
By trial and error, I found two custom properties of this control that I needed to set from VBA code: URL and uiMode (yes, that’s how it is capitalized).
Initially, the control looks like a scaled-down version of the full Windows Media Player. The Windows Media Player control is placed on an Access form using the Insert|ActiveX Control menu (it is way at the bottom of the list). So in the end I just tried everything I could think of, until finally I found something that worked.
As is often the case with ActiveX controls placed on Access forms, there is no Help attached to the control, and the Microsoft Knowledge Base and MSDN articles were not very helpful, lacking useful code samples for VBA or even VB (in fact, some help topics labeled as VB Code actually contained C++ code). Working with the Windows Media Player Control on an Access FormĪlthough eventually it turned out to be very easy to use this control from VBA code, it wasn’t trivial figuring that out. But now, with the Windows Media Player control, you can easily play an audio or video file, with only a few lines of code. But if you want something more sophisticated, say playing a piece of music or a video, it wasn’t so easy.
Since the earliest days of Access, you have been able to sound a beep from Access code, or a macro (the code is simple: DoCmd.Beep). Playing audio and video files using the Windows Media Player Control.