Help with exporting Illustrator CS4 datasets

I have written an applescript to loop through all the datasets in an illustrator file.


	tell application "Adobe Illustrator"
			activate
			import variables document currentDoc from alias XMLfilePath
			-- save a master ai file for all datasets
			--'set mysetcount to number of items in fileList
			repeat with idata from 1 to number of items in fileList
				display dataset idata of document currentDoc
				set mynewfile to exportFolder & "chart" & idata & ".ai" as string
				set myFile to file path of document currentDoc
				save document currentDoc in file mynewfile as Illustrator
				close document 1 saving no
				open myFile
			end repeat
		end tell

It works but after the first loop it throws up an error at “display dataset” saying file/folder expected.
any ideas as to solving this problem would be fantastic.
The currentDoc variable holds a link to a chart master file, (this file is saved in CS4.ai format)

Model: G4
AppleScript: 2.1
Browser: Safari 531.22.7
Operating System: Mac OS X (10.4)