Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Access and Access VBA > Access VBA
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Access VBA Discuss using VBA for Access programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Access VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 7th, 2007, 10:35 AM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Creating Media Player 11 Object in Access VBA

A few years ago, I wrote a Microsoft Access VBA script to copy and filter/sort/search my Windows Media Player database. It worked fine with Media Player 9 and 10, but now that I’ve ?upgraded? to Media Player 11, it has stopped working. The problem comes at the start, when I try to create a Media Player object.

In the past, this had been accomplished by the line:

Set objPlayer = CreateObject( “WMPlayer.ocx”)

But using Media Player 11, this line produced < -2147467259 automation error>. (By the way, the original line still works, when used in VBS script.)

In trying to get the script to work, added the Windows Media Player active-x control to the Access form, and made some changes in the script. The current version uses the lines:

Dim objPlayer As WindowsMediaPlayer
Set objPlayer = CreateObject(WindowsMediaPlayer, “WMPlayer.ocx”)

The second line fails with the error message <429 Active-X component can’t create object>. If I handle the error with Resume Next, the next line (Set objMedia = objPlayer.MediaCollection) fails with error message <91 Object variable or with block variable no set> because objPlayer hasn’t been created.

I have tried running this code on a normal command button, both with and without the Windows Media Player active-x control on the form. I've also tried placing the code in the media player control itself. I’m running Office 2003 on XP Pro, with Access running in Access 2000 and 2003 mode.

How can I create a Media Player 11 object in an Access VBA script?
Reply With Quote
  #2 (permalink)  
Old April 11th, 2007, 06:04 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi LouG

Sorry for the delayed reply, been meaning to reply to this one for a while.

Now Ive not used WMP in forms myself as sadly most my business work doesnt let us have in-software players for fun!

Right, you say you have added the WMP control to your form yes?

I have done the same and called the control "wmp".

All you then need to do is in your form code:
Code:
    Dim player As WindowsMediaPlayer
    Set player = wmp.Object

    With player
        'Enter code here.
    End With


You now have access to all the properties/methods of the object, although I cant help with those as I have never used them!

Hope this helps,
Regards,
Rob

Reply With Quote
  #3 (permalink)  
Old April 11th, 2007, 01:29 PM
Registered User
 
Join Date: Apr 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

THANK YOU SO MUCH. Your solution worked perfectly.

Isn't it amazing that in Microsoft's own Media Player 11 SDK, the coding instructions provided for this most fundamental WMP operation won't work in Microsoft's own Access VBA, and Microsoft didn't bother to say so, let alone tell users what to do instead?

Anyway, thanks again.

Lou
Reply With Quote
  #4 (permalink)  
Old April 11th, 2007, 04:54 PM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Oh yeah, M$ are notoriously brilliant at supplying documentation for all the controls people really need documentation for! =D

Glad to be of help,

Rob

Reply With Quote
  #5 (permalink)  
Old July 25th, 2007, 09:04 PM
Ald Ald is offline
Registered User
 
Join Date: Jul 2007
Location: Verdun, Que, Canada.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Lou,

I've been trying to incorporate WMP 11 into my Microsoft Access 2003 database of my CDs and DVDs. I'm a beginner in Access VBA. I was searching the Web to find help on how to do it when I found your posting from last April.

I tried what Robzyc wrote you back and it's working. The only reference I have is the Object Browser to figure out how to use Play, Stop, Pause, etc..

Would you know where I could find a reference on all the properties/methods of the object to be used (specially on how to load and use PlayLists ?

Thanks

Alan from Montreal

Reply With Quote
  #6 (permalink)  
Old July 26th, 2007, 03:38 AM
Friend of Wrox
 
Join Date: Mar 2007
Location: Hampshire, United Kingdom.
Posts: 432
Thanks: 0
Thanked 1 Time in 1 Post
Default

Alan,

Not sure off my head, but once you have created a reference, it should appear in your object browser (F2 within the Code Editor), then search for playlist and see if anything comes up!

Good Luck, if you have no joy, then let me know!

Regards,
Rob

<center>"Nothing can stop the man with the right mental attitude from achieving his goal;
nothing on earth can help the man with the wrong mental attitude".

Thomas Jefferson</center>
Reply With Quote
  #7 (permalink)  
Old July 31st, 2007, 04:02 PM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I'm a Java developer but I'm running into the same problem that you described here. I've searched the web but I can't find anything except for what you've discussed here.

When I try to create the OLE object using "WMPlayer.ocx" as the program id, I get the same -2147467259 automation error. This used to work in previous versions of Windows Media Player.

I'm just trying to gather some info so that I can make my java code works again.

Can you tell me exactly what you had to do to make your call:

Set objPlayer = CreateObject(“WMPlayer.ocx”)

to work again? I have the equivalent call to CreateObject in Java.

Thanks,
Duno
Reply With Quote
  #8 (permalink)  
Old July 31st, 2007, 07:42 PM
Ald Ald is offline
Registered User
 
Join Date: Jul 2007
Location: Verdun, Que, Canada.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by duno2002
 I'm a Java developer but I'm running into the same problem that you described here. I've searched the web but I can't find anything except for what you've discussed here.

When I try to create the OLE object using "WMPlayer.ocx" as the program id, I get the same -2147467259 automation error. This used to work in previous versions of Windows Media Player.

I'm just trying to gather some info so that I can make my java code works again.

Can you tell me exactly what you had to do to make your call:

Set objPlayer = CreateObject(“WMPlayer.ocx”)

to work again? I have the equivalent call to CreateObject in Java.

Thanks,
Duno

Duno, I'm a real beginner at this stuff. Here is what I did:
    In MS Access, in my main form VBA Code, I put:
          Option Compare Database
          Dim player As WindowsMediaPlayer
          Set player = WMP.Object
    after I drag & drop the WindowsMediaPlayer control from the tool bar "More controls" button. This is giving you the Play, Pause, Next...buttons. When you look at the "properties" of this control, (in design mode of the form) you can see the following:
       Name : WMP (my own choice of name here)
       OLE Class: Windows Media Player
       Verb: 0
       Class: WMPlayer.OCX.7
In the Event "On Got Focus" event procedure I have the following code: WMP.URL = MyFile
where MyFile is the full path of a .MP3 file or a .WPL file (playlist create with the real Windows Media Player) and plays it.

So far, so good.

My next step is to work with the Playlists. I Have not been able to load a playlist and get each item specs (Title, Artist, duration,...)
Some how, by using a *.WPL file with the command WMP.URL, it is considered as a url not as a playlist. It plays it but I can't figure out how to get playlist details. Since I'm a beginner, I'm struggling with the different syntax of methods / property / action / etc... of the Object Browser.

Hope this will help you.

If ever you have some sample code on how to used and code all of these "methods / property / action / etc..." I would appreciate it.

Thanks

Al
Reply With Quote
  #9 (permalink)  
Old August 1st, 2007, 10:58 AM
Registered User
 
Join Date: Jul 2007
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Al for your quick response.

It appears that VBA is doing a lot of "magic" behind the scene to set up WMP for you. Unfortunately I don't have anything like that for Java.

Duno
Reply With Quote
  #10 (permalink)  
Old October 20th, 2008, 08:50 AM
Registered User
 
Join Date: Oct 2008
Location: Atlanta, Georgia, USA.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by robzyc
 Hi LouG

Sorry for the delayed reply, been meaning to reply to this one for a while.

Now Ive not used WMP in forms myself as sadly most my business work doesnt let us have in-software players for fun!

Right, you say you have added the WMP control to your form yes?

I have done the same and called the control "wmp".

All you then need to do is in your form code:
Code:
    Dim player As WindowsMediaPlayer
    Set player = wmp.Object

    With player
        'Enter code here.
    End With


You now have access to all the properties/methods of the object, although I cant help with those as I have never used them!

Hope this helps,
Regards,
Rob

hey rob

im really wet behind the ears on this code
im working on access 2007 having problems
making windows media player run you also mentioned
using a form code if im not mistaken, where and
how can i retrieve this, like i said really new
to this would really appreciate your input

would love to see a copy of code as it seen on the application
if possible?
All you then need to do is in your form code:
Code:
    Dim player As WindowsMediaPlayer
    Set player = wmp.Object

    With player ????
        'Enter code here.????
    End With
    ?????

thanks

Edmund


Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Media player in PHP tanzi PHP How-To 0 July 21st, 2008 12:53 AM
Windows Media Player 10 gigamars04 VB.NET 1 December 17th, 2007 12:12 AM
Media player COM reference Apocolypse2005 Visual Basic 2005 Basics 2 November 4th, 2007 12:14 PM
Windows Media Player 1g0r Pro VB 6 0 October 16th, 2006 01:51 AM
Creating a Media player(mainley mp3 and wma) Apocolypse2005 Beginning VB 6 0 June 7th, 2005 12:50 PM



All times are GMT -4. The time now is 12:54 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.