Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

condition to check if playlist in itunes does not exist

Status
Not open for further replies.

pujas

Programmer
Feb 2, 2005
22
0
0
US
I have written the below function

what it does is either ceates a new playlist in itunes or if the same playlist exist it will not create a new playlist but just add files to the existing playlist



Public Function CopyAudioToiTunes()
PlaylistName = "Puja"
Set iTunesApp = CreateObject("iTunes.Application")
Dim Albumplaylist
Set Albumplaylist = iTunesApp.LibrarySource.Playlists.ItemByName(PlaylistName)
If Albumplaylist.Name <> PlaylistName Then
Set Albumplaylist = iTunesApp.CreatePlaylist(PlaylistName)
MsgBox "Creating new Playlist" & Albumplaylist.Name
End If
Dim FilesArray(0) As String
FilesArray(0) = mp3folder 'some global var defined before

Albumplaylist.AddFiles (FilesArray)
MsgBox ("Created playlists and added audio files to itunes.")

End Function

Its giving me an error:
object var not set
at this line : If Albumplaylist.Name <> PlaylistName Then

Basically i tried to check for all values like
if Albumplaylist = NULL then

or
if Alubumplaylist = "" then

but its still giving me an error

Could someone pls suggest me what condition to look for when the playlist does not exist.

Thanks
 
I guess if i can find out a way in VB to check if a object is set or not set then i'll be able to make the above work.

Can some pls tell me how do you check if a object is set or not
 
Perhaps this ?
If Albumplaylist Is Nothing Then

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
i got it to work

Set Albumplaylist = Nothing
Set Albumplaylist = iTunesApp.LibrarySource.Playlists.ItemByName(PlaylistName)
If Albumplaylist Is Nothing Then
Set Albumplaylist = iTunesApp.CreatePlaylist(PlaylistName)
MsgBox "Creating new Playlist" & Albumplaylist.Name
End If
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top