# Adding WindowsMediaPlayer to a form...At runtime.



## Steve_ (May 17, 2019)

Just like the Title says..

I am trying to figure out how to add a WindowsMediaPlayer control to a form via code. I am not able to find the correct syntax for it. Apparently, it is not done the same way as adding MSForms controls such as labels, texboxes, commandbuttons, etc..

Has anyone seen this done before?


----------



## daverunt (May 17, 2019)

This might help...?
Translated

https://translate.google.com/transl...l-windows-media-player-en-un.html&prev=search


----------



## Steve_ (May 17, 2019)

It does not include syntax for programmatically adding the control. Only manipulating one that is already on a form. Sadly, my project does not contain forms or controls. this is all created on the fly at runtime and destroyed afterwards.


----------



## Steve_ (May 17, 2019)

Or, does anyone else know a way to reliably play background music on a form?


----------



## Steve_ (May 19, 2019)

/bump


----------



## Domenic (May 19, 2019)

First, set a reference to Windows Media Player (Visual Basic Editor >> Tools >> Reference).  Then try something like this...


```
Private Sub UserForm_Initialize()

    Dim objPlayer As WMPLib.WindowsMediaPlayer
    
    Set objPlayer = Me.Controls.Add("WMPlayer.OCX.7")
        
    With objPlayer
        .Left = 10
        .Top = 10
        .Url = "http://stream-dc1.radioparadise.com/aac-320"
    End With
    
End Sub
```

Hope this helps!


----------



## Steve_ (Jul 19, 2019)

Domenic said:


> First, set a reference to Windows Media Player (Visual Basic Editor >> Tools >> Reference).  Then try something like this...
> 
> 
> ```
> ...




OMG! This got away from me! I did not see your reply. This works perfectly and was easily adapted to my runtime-built forms. Thanks!


----------



## Domenic (Jul 19, 2019)

You're very welcome, and thanks for the feedback.

Cheers!


----------

